How do I update the panel launcher icon?

I have a .desktop file in a launcher on the panel. I want to be able to update the icon used for it from a script.
I run Zorin OS 15.3 education lite.

Any help is welcome!

Originally asked on Unix and Linux Stack Exchange: https://unix.stackexchange.com/questions/633714/how-do-i-update-the-panel-launcher-icon

That seems like a PlayOnLinux installation. In POL, right click on the shortcut and select Set the Icon.

It’s definately not PlayOnLinux, it’s a .desktop file for a script I wrote.

You can give the path to the icon in your script with

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/usr/bin/codeBodger
Name=codeBodger
Comment=Custom-program
Icon=/path/to/icon/icon.png

Replace all above portions with your actual program and actual path and icon name.

I already have that. That’s what the launcher runs. I have changed the icon file (but kept the name the same) and I would like to have a script that I can run to update the icon displayed in the launcher on the panel.

I am not following. Are you trying to create a script to run to change the icon temporarily or on an ad hoc basis from the one you have listed in the .desktop entry?
Because otherwise, you do not need any other script. You need only to amend the existing .desktop entry with the new icon path and file name.
If you change the entry but want to update the panel to see the changes without logout/in - you can hit alt+F2 and type in

r

Right.
I have a shell script AltGr
I have a desktop configuration file AltGr.desktop
I have two icon files AltGr.png and AltGr1.png which are in the same directory.
In AltGr I have the lines:

mv ~/.local/icons/AltGr.png ~/.local/icons/AltGr0.png

mv ~/.local/icons/AltGr1.png ~/.local/icons/AltGr.png

(I don’t know what happened to the highlighting. It’s supposed to be bash)

I would like to add code after these two lines to make this change effect the launcher that I have on the panel. This launcher goes to AltGr.desktop which contains the line
Icon=/home/codeBodger/.local/icons/AltGr.png
This is the path to AltGr.png.
While not ideal, if a solution similar to alt+F2 and then typing r is the only option, that is OK. I can use xdotool.

I am confused as to what alt+F2 and then typing r was supposed to do, as r didn’t actually do anything. I couldn’t even hit Enter.

Thanks.

Alt+F2 with then entering “r” restarts the Gnome-Shell. Restarting Gnome Shell then allows you to see changes made to the shell configuration.
Alt+F2 does enter, it just does not drop down a line. If you hit enter and the popup window closes without error- then it worked.

…Are you trying to create an Animated ever changing Desktop Icon?

Is alt+F2 supposed to open “Application Finder”?
When I type r into the Application Finder and hit enter, it just gives this: Screenshot_2021-02-11_14-29-55

I am not trying to make an ever changing icon. I have a “launcher” on the “panel” that goes to a Desktop Configuration file. I would like to add to the script (referenced by the Desktop Configuration file) some lines of code to refresh the panel, like what alt+F2 then r is supposed to do (I think).

I don’t mean to seem blunt (if I do seem so), and I am very grateful for all help!

OK- it looks like you are using Zorin Lite- which is XFCE. Application Finder is only on Zorin Lite.
In Gnome- it would restart the Gnome-Shell (Zorin Core and Zorin Ultimate).
My hats off to you for choosing Zorin Lite. It is a great desktop.

To restart the panel in XFCE or Zorin Lite, enter into Alt+F2 instead

xfce4-panel -r

To restart the Desktop in XFCE or Zorin Lite, enter in:

xfdesktop --reload

That being said... The only reason I could possibly see to place the

mv ~/.local/icons/AltGr.png ~/.local/icons/AltGr0.png

within its own bash script would be if you wanted to constantly rotate the icons out with eachother in order to create an animated desktop icon.
Which Would Not Work, By the Way.

If all you want to do is to replace the icon- then enter the applicable mv command into your Terminal. Replace the icon with the new one... One Time Only... Then use Alt+F2 to

xfdesktop --reload

or restart the panel in order to see the changes.

And for the Curious - Since the suggestion was made by me asking if the OP was trying to create an animated icon: No, that cannot be used to create an animated Icon on the desktop- before anyone starts asking. For one thing, either Gnome-Shell or XFCE4panel would need to be constantly restarted and that would not only be bad for the system after a while, but it would also bog the system down to the point of being unusable.
IF I wanted to create an animated Icon on my desktop, I would probably use a Lua Script to make an animated Conky that is background, then place a Transparent Icon on top of it. (And this may not even work on the New XFCE due to how XFCE changed how it handles desktop transparency.)

Bash Scripts are used for Repetitive or Repeatable actions, not for a one time change.

1 Like

I don’t know exactly what everything you said there was, but xfce4-panel -r worked wonders!

Thanks so much!

1 Like

Please remember that Bash Scripts are for actions that you want to repeat as a command. For one time actions, please use the terminal.
To use a terminal command in a bash script, you also will want to set the script to Run In Terminal mode.
So bash scripting was not what you needed here.
Just straight terminal.