Refresh launcher's icon without restarting xfce4-panel

141 Views Asked by At

I have a shell script that replaces a favicon used as an image for a xfce4-panel launcher. I'm looking for a solution to refresh the launcher's icon without restarting xfce4-panel.

Restarting xfce4-panel as root could cause various issues, such as errors when trying to restart the server through the CentOS UI, as the session is launched by another user. I attempted to restart xfce4-panel using commands like "sudo -u USER xfce4-panel --replace," but the issue still persists.

1

There are 1 best solutions below

0
aelomari97 On

After differents days of searching, i have discovered a solution to force xfce4-panel to refresh icons without restarting it. The solution involves editing the configuration file of the xfce4-panel launcher. By modifying the file, xfce4-panel recognizes that changes have been made and refreshes the launcher, including the associated icon.

So the code that i have integrated in my script is the following :

# path that includes directories of launchers and their corresponding configuration files

launchers_path="/home/USERNAME/.config/xfce4/panel"

# name of the launcher that you want to update

launcher_name="MyLauncher"

# loop over each launcher configuration file that contains the name of the launcher to update

for launcher in $(grep -rl $launcher_name $launchers_path); do

    # using sed to replace "favicon.ico" by the same name in order to edit the file and force xfce4-panel to refresh the launcher

    sed -i 's/favicon.ico/favicon.ico/g' $launchers_path/$launcher

done

Upon reading this solution, it's natural to find yourself asking some questions :

  • Why did i use a loop?

The reason is that the folders of the launchers are named "launcher-N" where "N" represents the number of the launcher, possibly indicating the order of creation for each launcher. To ensure accuracy, i chose to iterate over each configuration file that contains the name of the launcher i wanted to update, in order to locate the corresponding configuration file.

  • Why did i replace "favicon.ico" with the same name?

In my particular case, the file "favicon.ico" is replaced just before in the first script. Therefore, the workaround i employed was simply to edit the file and trigger the refreshing of the launcher's image by xfce4-panel. In your case, you can utilize the path or name of the new image.

Other informations :

Before this solution, i attempted to use touch configuration_file command to update the file's date and force a refresh, but it did not work.