Change Panel icon on the fly

Style your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Change Panel icon on the fly

Post by aborup »

Hello all. I hope I am posting in the correct place.
I am using Mint Mate 20.1

I have a launcher in my panel that fires a script that toggles my VPN on or off when it is clicked. I would really like the launcher's icon to reflect the current state of the VPN. If it is connected, then I want the icon to be yellow otherwise green (both icons exist). I have located the directory where my panel's launcher properties are stored: $HOME/.config/mate/panel2.d/default/launchers. I can edit my launcher file and change the name of the icon there, but it is not immediately reflected in my panel. I must log out and back in for the new icon to appear. Is there a way for me to have this change immediately reflected?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

Bump. Nobody has a notion about how to do this?

I know it can be done, my battery icon is an example. It changes when plugged in or out. Also, my network icon changes with status. I just want to know how that's done so I can make MY icon change with status.
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

Wow! It looks like you are going through lots of troubles to get this... You are using or creating your own custom script for such a standard feature... Well, i don’t know about Mate, but on Cinnamon, you don’t have to go through lots of troubles to get what you want. You could just click on the Network icon in the notification area and add your VPN in the settings. Well, it is not that simple. The complete story can be found here: https://www.expressvpn.com/support/vpn- ... h-openvpn/ This Ubuntu Network Manager is the same as the one in Linux Mint Cinnamon 20.1.

After about 15 minutes spent on carefully following these instructions, you will notice your Network icon will change depending on your connection type:

VPN connection ON
VPN connection ON
VPN connection OFF (regular "Wired" connection)
VPN connection OFF (regular "Wired" connection)

Of course, you only have to do this 15 minutes manual Network configuration once, and after that, all you have to do is click your VPN on or off.
Last edited by sebastjava on Sat Mar 20, 2021 1:01 pm, edited 1 time in total.
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
llovepancakes
Level 1
Level 1
Posts: 34
Joined: Sun Jun 21, 2020 11:02 pm

Re: Change Panel icon on the fly

Post by llovepancakes »

thats a cool little VPN pic in that link. but i dont really want to screenshot with that, maybe something discreet lol. OP making us one?? hahaha
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

Thanks for the feedback!
I will experiment with that for my VPN needs.

However, my original question is still needing an answer:

How does one update an icon in the panel on the fly without having to reload the whole panel?
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

I think i am getting close to finding some good methods. I just have one question for now: are you on Mint Cinnamon, Mate, or Xfce? It looks like you are on Mate but i just want to make sure... I am on Cinnamon... Things could be a bit different from one flavour to another.

I should wait, I'm here in the middle of the night. I will complete this work later, more neatly. But here's a quick summary of my adventures so far...

I created this one line script and saved it in /usr/local/bin/switch-icon:

Code: Select all

#!/bin/bash

aplay /usr/share/sounds/linuxmint-login.wav
Then i went into right-click on Menu > Configure > Menu tab > Open the menu editor.

Using this Menu editor, i clicked on New Item and added my /usr/local/bin/switch-icon command named Switch-icon in the Accessories sub-menu.

Then, i did a right-click from the Menu > Accessories > Switch-icon to add my new launcher to the Panel.
So now, i have a launcher in the Panel, and when i click on it, it plays a test script, just a login sound for now.

Next, i go back to the Menu editor, select my Switch-icon, click on Properties, click on the icon, and change it to "network-vpn-symbolic" icon. And while being in this search and select window, i looked at all the other network icons, and i saw there was also a "network-wired-symbolic", among many others. So, for this little experiment, i want to find a way to switch instantly from "network-wired-symbolic" icon to "network-vpn-symbolic" icon. Back and forth.

Still in the Menu editor with Switch-icon selected, i clicked on Edit Desktop File. It opened this:

Code: Select all

[Desktop Entry]
Name=Switch-icon
Exec=/usr/local/bin/switch-icon
Comment=Switch icon and play sound (test)
Terminal=false
Icon=network-vpn-symbolic
Type=Application
So that’s where the Icon is set. Each time i change the launcher icon from the Properties in the Menu editor, this file gets updated. This file is located there: ~/.local/share/applications/alacarte-made-df13e28a-89fb-11eb-a96c-8ba96b586f54.desktop

But i wonder if there is another copy of this file somewhere else, for the panel? When i right-click the launcher in the Menu Accessories to Add to desktop, it does create a duplicate of this launcher-filename.desktop on the ~/Desktop. But the only thing i could find relevant for the panel is this ~/.cinnamon/configs/grouped-window-list@cinnamon.org/*.json The launcher-filename.desktop is listed in there when pinned from the Menu. Anyway, whether in the Menu, on the Desktop or pinned in the panel's Grouped window list, the true filename for this launcher always starts with "alacarte-made". So i just did a quick "Search for Files" in Nemo and only found 2 copies: one in ~/.local/share/applications/ and the other in ~/Desktop.

More frustrating, when i update the Icon=iconname by a direct edit in this launcher-filename.desktop, the Menu icon gets updated instantly, as well as the Desktop icon, but not the Panel icon. But, as soon as i close the Menu editor, then the Panel gets updated. So i wonder what is happening under the hood when i close this Menu editor.

Searching the web, i found someone had to rename twice /home/user/.cinnamon/configs/panel-launchers@cinnamon.org/*.json to refresh the panel. So, I came up with a better solution:

Code: Select all

touch ~/.cinnamon/configs/grouped-window-list@cinnamon.org/*.json
does the job. So this way, i can edit the ~/.local/share/applications/launcher-filename.desktop, then do this touch, and the Panel icon gets changed!

This little experiment is not done yet, still to come:
  1. I should try these things on Mate, maybe, on my little Netbook...
  2. I want this launcher-filename.desktop to be changed from the script, using some sed command. So, you click on the small icon in the Panel, you hear a login sound and the icon is changed to network-vpn-symbolic. Click again, and you hear a logout and the icon gets changed to network-wired-symbolic. Creating some sort of toggle switch. I guess all i need is a combination of sed, if / else, and touch commands...
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

Yes indeed, I am running Mint on all my machines.

I have located the directory where my panel's launcher properties are stored: $HOME/.config/mate/panel2.d/default/launchers. I can edit my launcher file and change the name of the icon there, but it is not immediately reflected in my panel. Perhaps your example of a "touch" would make the panel do just what I want, but I don't know what to "touch".

This panel launcher's purpose is to trigger a script that I call "CyToggle". It checks to see if Cyberghost VPN is running or not. If not it starts it else it stops it. It also uses notify-send to tell me what it is doing and the result. In addition, my "kludgy" way of always knowing the status of the VPN is to have that script copy an empty file to my desktop with an appropriately colored icon that gives me an immediate visual clue about the VPN status. That is why I am trying to simply update the color of the icon in my panel so I can do away with the file copying to the desktop.

I would be happy to post my "CyToggle" script if anyone is interested. Pretty simple and far from elegant.
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

aborup wrote: Sun Mar 21, 2021 6:26 pm Yes indeed, I am running Mint on all my machines.

I have located the directory where my panel's launcher properties are stored:
$HOME/.config/mate/panel2.d/default/launchers.

I can edit my launcher file and change the name of the icon there, but it is not immediately reflected in my panel. Perhaps your example of a "touch" would make the panel do just what I want, but I don't know what to "touch".
[...]
Yes, you are running Mint, okay. But there are currently 3 different Mint flavours:
  • Linux Mint Cinnamon
  • Linux Mint Mate
  • Linux Mint Xfce
So my question was, and still is, which one of these are you using? That is very important because the answer to your question will differ depending on which "flavour" or "version" you are using. Anyway, just looking at this $HOME/.config/MATE/panel2.d/default/launchers you are talking about, i guess you are on Linux Mint MATE. So, i will power up my old little Netbook to do some tests on MATE...

"My panel's launcher properties"? I hope we are talking about the same kind of file. The one i am looking at is some launcher-filename.desktop.

Yes, this touch seems to be the missing piece in this puzzle. Here on Cinnamon, i get the same story as yours. I can edit some launcher-filename.desktop to change the launcher icon, on the Panel. But, just like you were saying, i would have to logout/login or something to refresh the Panel. So, i tried this touch and... bingo! The icon gets changed instantly.

But here i am just talking about some Cinnamon experiments... I will re-work all this on MATE, soon...

I am pretty confident i will be able to find the answer you are looking for. I will go even further. I want to make a little script that toggles between 2 icons when you click on it. Exactly what you were talking about, if i got it right. In fact, i was 99.9% sure i almost got it, on Cinnamon, but it seems i have to restart all this search again for MATE, on my ultra small (and slow!) old netbook...
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

Thanks for your efforts! Yes... Indeed I meant to type MATE but my mind typed Mint.
And yes... the file I found where I can change the panel icon is cytoggle.desktop in the directory I mentioned above.

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=/home/al/Icons/CyConnected.png
Icon[en_US]=/home/al/Icons/CyConnected.png
Name[en_US]=cytoggle
Exec=/home/al/MyBin/cytoggle
Name=cytoggle
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

Okay, thanks for this information. Oh, sorry, i just saw you already mentioned this in the first lines of your OP. Now i know you are on Mint MATE 20.1 and that's all i needed to know.

So, i am trying things on MATE now. Short story, i still have hopes that what you need is a touch command. But i can’t find where is this file to be touch-ed. This file i am desperately looking for is the configuration file for the Panel. Touching it would hopefully update the panel with the changed icon. It works with Cinnamon, this way:

Code: Select all

touch ~/.cinnamon/configs/grouped-window-list@cinnamon.org/*.json
But i can’t find this kind of file on MATE. I'll try looking at things from the Dconf-editor, maybe i could learn how the panel user configurations are stored by looking at things from this Dconf-editor...
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

I haven't given up yet, but I'm starting to lose confidence... But i think i might start to consider trying to do things in a more standard, diplomatic way. These panel icons on the left are just not supposed to be changed on the fly. On the other hand, on the right side of your screen, there is this system tray, or notification area. There are some standard procedures implemented into this system tray to get all sorts of notifications, including icon updates. Food for thoughts...
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

Hmmm... I have been away on a short trip but can now get back to this. Not sure how to add to the system's notification area or manipulate that. I am wondering if my solution might be to kill mate-panel and relaunch it via my script. Sounds a bit heavy-handed though.
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

aborup wrote: Sun Mar 21, 2021 6:26 pm [...] I would be happy to post my "CyToggle" script if anyone is interested. [...]
Yes, please show me this script.

Some news
I am having a hard time trying to gather informations about the system tray, also called the notification area. I don't know much. I can't be sure what follows is all exact, true informations. But I'll give it a try... Please correct me if needed.

The system tray is part of the panel. Usually on the right side. The icons in there can be changed instantly to show some status. They are called StatusNotifierItems (also known as AppIndicators). I looked into the Dconf editor on MATE and learned a few things. I found org > mate > panel > objects > notification-area. I saw the notification area is an applet. So, a regular launcher is an individual, separate object, while things are different for the StatusNotifierItems. For example, the launcher-caja and the launcher-terminal are 2 separate objects. But the mintUpdate, network, sound, and battery items are all controlled by the notification area applet, apparently. I right-clicked the first item in this notification area and those 4 items moved as a whole, so...

That is all in MATE. At least, just by looking at Dconf and playing with things, i get an idea of how things are working. But i had more trouble in trying to understand how things work in Cinnamon. All this is just my first "clues" anyway. Any help would be appreciated. I find it hard to get some introduction on these things. Oh yeah, i was already forgetting this MATE Panels tutorial here on the Mint forums. There is a small but interesting part on the system tray:
hydrurga wrote: Sat Aug 08, 2020 8:00 am [...]
Notification Area applet
Also known as the system tray, this provides applications which use it with a means of providing icons that indicate their status, and includes for example the power, update, network and volume icons. There appears to be no way in MATE to tell the Notification Area applet which of these should be shown or hidden, and so usually you have to resort to the program itself in the hope that its configuration options include such a setting. These settings might be available by right-clicking on the application's icon in the notification area. For the power manager icon, you can run mate-power-preferences.
[...]
The MATE notifications area, here framed in red
The MATE notifications area, here framed in red

Anyway, i just needed to sum up my findings here, and share. Let's get a bit faster, shorter, down to the point. I think you should use this system tray. It makes sense. I wanted to participate and do some fun experiments with it but this is getting heavily time consuming. It looks very complicated. Maybe I'll just hand over the baton.

There are possibly many ways to create these clickable status icons. I am still not sure, but maybe.
  • It could be some Python-GTK script. But this looks seriously complicated.
  • It could be some C+GTK applet. But that's the top. The most complicated.
  • It looks like it could be done by using the Yad application. It is right there, in your Software Manager: "Yad allows you to display GTK+ dialog boxes from command line or shell scripts. It is similar to Zenity but with more dialog types and options." Yes, there are many options. It still looks quite complicated, at first sight. But they added this https://sourceforge.net/p/yad-dialog/wi ... ationIcon/ for the system tray recently. But i can't find much information or any example for this, so far. There is also a forum where to get some help about Yad: https://groups.google.com/g/yad-common?pli=1 To be continued...
  • I also tried this Gtrayicon, also available in your Software Manager. "Generic tray icon for GNOME is a small utility which allows to add an icon to the system tray that can be used to trigger customized enable/disable actions." This one is far too good in many ways. It is some sort of small applet written in C language. That's the topmost professional language. I am not an expert, but i downloaded the source directory and took a quick look and it looks all very clean and professional. It is very complicated on the hidden back-end, and perfectly simple, easy to use for us, the front-end users. It is just too good. It already has the toggle function included, so you would actually have to trim down your shell script to remove the "push-on-push-off" function, since this cute changing icon in the system tray could send something like cytoggle on and cytoggle off commands... So, this one is very easy and looks very nice. Of course, you can customize your icons for both the on and off states. But... Arrrgh. NO! I am sorry but i think there is one major problem there. Please confirm or not. I am afraid there is one essential thing missing on this cute little Gtrayicon. It sends commands for the on and the off states. And changes icons accordingly. But it does not take any input from the command line. So... there is no way to tell Gtrayicon that your VPN connection failed. No way to get it to automatically switch back to the off state from the shell script. Once this Gtrayicon is started, the only input it takes is... your mouse clicks! You can't be happy with this, IMHO.
So, i would just keep trying this Yad...
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

There is one fundamental thing that you already know but that is worth remembering.

Think about this word again: shell. A shell script is some external process. It is a combination of command line interface (CLI) and a set of instructions to automate your repetitive tasks. Of course, you have more options on the command line interface (CLI) in comparison with the graphical user interface (GUI). But it is still the same kind of operations. A shell script only allows you to automate things that could be done using some file manager or text editor. More or less. There are also some other applications that are accessible through CLI. But i guess that changing a launcher icon "on the fly" is just not normally possible using only standard shell commands.

Maybe not. Maybe you can be imaginative and find a way to achieve this. Like "killing" the panel, as you were saying. That is a clever idea, but i really don’t like this idea of "killing" a part of the desktop that is doing a good job. This makes a bad karma. :) I am not trying this.

So, your script will need some help from the inside. Something like the Yad package. Or, last resort, you could try some modifications on the Gtrayicon source code and build your own applet. But that is ultra-complicated and would take me a very long time. There would be a lot of things to learn before I could get any good results.
Last edited by sebastjava on Tue Mar 30, 2021 2:38 pm, edited 1 time in total.
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

News...
It looks promising. I installed this YAD package. I succeeded in doing some basic commands, but i am still far from the complete, well working script.
At present time, i see i can get this YAD to display an icon in the system tray. And then get some command when this icon gets clicked. And... i can change this icon "on the fly". And this works on both MATE and Cinnamon:

Code: Select all

#!/bin/bash

# NEEDED:
# YAD-test file Properties > Permissions: Allow executing file as program
# apt install yad

echo; echo; echo; echo
echo "TEST THIS yad package..."
echo "1. Left-click the icon to: aplay /usr/share/sounds/linuxmint-login.wav..."
echo "2. Copy-paste using Shift+Ctrl+C and Shift+Ctrl+V to change the icon:"
echo
echo "icon:/usr/share/icons/Mint-X/status/scalable/network-vpn-symbolic.svg"
echo
echo "3. Change it back with another copy-paste:"
echo
echo "icon:/usr/share/icons/Mint-X/status/scalable/network-wired-symbolic.svg"
echo
echo "To exit, just type 'quit'"
echo

yad --notification                                                                \
    --listen                                                                      \
    --image="/usr/share/icons/Mint-X/status/scalable/network-wired-symbolic.svg"  \
    --text="Notification test tooltip"                                            \
    --command="aplay /usr/share/sounds/linuxmint-login.wav"
But i want to create a script that will alternate between ON or OFF at each time you click this tray icon. And then update this tray icon to reflect the ON or OFF states. This sounds easy, but i am having big troubles here. I need to make a pipe to communicate between 2 scripts. I never did that before so i am lost. So, this YAD would be a child script and would send a "toggle" function call to the parent script, the one that does the "toggle" function. And this parent script would then echo "icon:some_new_image" to this child script YAD. That is how i see this. I don’t know how to get this. I should leave this YAD aside for now and just try to build some pipe between 2 very simple scripts, just to experiment...
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

How do I attach a script like you just did? Can't seem to figure that out quickly. I want to attach my "cytoggle" script.

My "cytoggle" script does everything I want except change the panel launcher's icon color. If the VPN is connected, it disconnects it. If not connected, it connects. It sends out a desktop notification of its actions and puts a "dummy" icon on the desktop that indicates the VPN's status, but it is not always reliable - especially if I unexpectedly logout.

I know exactly which file to modify to change the panel launcher's icon, and can easily add this edit to my toggling script. The panel simply needs to be refreshed after the change. This seems like it should be relatively easy. The utility that I think will work is "mate-panel" which has a "replace" option but I can't find any documentation on just how to use it!
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

Whoop whoop!

I have gotten this to work. The answer was to use "setsid mate-panel --replace >/dev/null 2>&1 < /dev/null &"
after I updated the cytoggle.desktop file to use the correctly colored icon.

I will put the completed script here once I can figure out how to upload it.
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

"How do I attach a script like you just did? Can't seem to figure that out quickly."
  • That's easy. In the POST A REPLY field, copy-paste or write your code.
  • Select All your code.
  • Click on the 5th icon above the writing field, the one that looks like: </>
You will get this:

Code: Select all

#!/bin/bash

echo "Hello world!"
Click to enlarge...
Click to enlarge...
P.S.: Click on Preview before you Submit !
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
aborup
Level 1
Level 1
Posts: 9
Joined: Sat Feb 20, 2021 6:40 pm

Re: Change Panel icon on the fly

Post by aborup »

Code: Select all

#!/bin/bash

# This script is used to toggle CyberGhost 
# - if connected, then disconnect it
# - if disconnected, then connect it

# Kill any other notifications that might be displayed at the moment.
# notify-send does not offer a way to "cancel" a previously sent notification, so
# the work-around is to kill the notify daemon itself.
killall /usr/lib/mate-notification-daemon/mate-notification-daemon

# Is the VPN running or stopped?  Go to the appropriate logic:
if /home/al/MyBin/cystatus |grep -q 'VPN connection found.'; then

   ######  CURRENTLY RUNNING #########
   # CyberGhost is currently running. We want to tell it to stop.
   notify-send -i $HOME/Icons/CyStopped.png "CyberGhost" "disconnecting..." -t 500000
   sudo cyberghostvpn --stop

   # Did it stop? 
   if /home/al/MyBin/cystatus |grep -q 'No VPN connections found.'; then

      # It has stopped. Copy an updated cytoggle.desktop file to the appropriate location
      # that has the correctly colored icon to indicate that Cyberghost is now stopped.
      rm /home/al/.config/mate/panel2.d/default/launchers/cytoggle.desktop
      cp /home/al/MyBin/cytoggle.desktop.stopped /home/al/.config/mate/panel2.d/default/launchers/cytoggle.desktop

      # Kill the ("disconnecting...") notification
      killall /usr/lib/mate-notification-daemon/mate-notification-daemon
      # Replace it with the following:
      notify-send -i $HOME/Icons/CyStopped.png "CyberGhost" "CONNECTION ENDED!" -t 5000
   else
      # It doesn't seem to have stopped.  Shouldn't ever happen, but notify the user.
      # Kill the ("disconnecting...") notification
      killall /usr/lib/mate-notification-daemon/mate-notification-daemon
      # Replace it with the following:
      notify-send -i $HOME/Icons/CyStopped.png "CyberGhost" "UNKNOWN ERROR! Not stopped!" -t 5000
   fi

else

   ######  CURRENTLY STOPPED #########
   # CyberGhost is currently stopped. We want to tell it to connect.
   notify-send -i $HOME/Icons/CyConnected.png "CyberGhost" "connecting..." -t 500000
   sudo cyberghostvpn --traffic --country-code US --connect

   # Did it connect? 
   if /home/al/MyBin/cystatus |grep -q 'VPN connection found.'; then

      # It has connected. Copy an updated cytoggle.desktop file to the appropriate location
      # that has the correctly colored icon to indicate that Cyberghost is now connected.
       rm /home/al/.config/mate/panel2.d/default/launchers/cytoggle.desktop
       cp /home/al/MyBin/cytoggle.desktop.connected /home/al/.config/mate/panel2.d/default/launchers/cytoggle.desktop
      
      # Kill the ("connecting...") notification
      killall /usr/lib/mate-notification-daemon/mate-notification-daemon
      # Replace it with the following:
      notify-send -i $HOME/Icons/CyConnected.png "CyberGhost" "CONNECTION STARTED!" -t 5000
   else
      # It doesn't seem to have started.  Not sure what happened?
      # Kill the ("connecting...") notification
      killall /usr/lib/mate-notification-daemon/mate-notification-daemon
      # Replace it with the following:
      notify-send -i $HOME/Icons/cystopped.png "CyberGhost" "UNKNOWN ERROR! Not started!" -t 5000
   fi
fi

# The icon of the launcher in the panel needs to be reloaded to reflect the new status of Cyberghost.
# The following script launches a new version of mate-panel.
PanelToggle
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

I finally found something that works. Tested on both MATE and Cinnamon. Just a starting base. But there are things in there that i don’t like. I am still trying to make things more clean and simple. I haven't done much yet. This is approximately just a copy-paste from some fix found in the https://groups.google.com/g/yad-common. I shared my thoughts about this script at the bottom of this script itself...

Code: Select all

#!/bin/bash

# Leave some space on top, otherwise it could get hidden by "The child process exited normally with status 0."
echo; echo; echo; echo

# Safely create a temporary file name: PIPE = /tmp/this_filename.random#4
PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXX)
# Create a FIFO file, used to manage the I/O redirection from shell
mkfifo $PIPE
# Attach a file descriptor to the file
exec 3<> $PIPE
# Add handler to manage process shutdown
function on_exit() {
    echo "quit" >&3
    rm -f $PIPE
}
trap on_exit EXIT
##################################################################################################################

# Add handler for tray icon left click
function on_click() {
    exec 3<> $PIPE # I DON'T LIKE THIS! Please read my bottom notes.
    echo "icon:/usr/share/icons/Mint-X/status/scalable/starred-symbolic.svg" >&3
}
export -f on_click # I DON'T LIKE THIS! Please read my bottom notes.
export PIPE # I DON'T LIKE THIS! Please read my bottom notes.

# Create the notification icon (default icon-size=16)
yad --notification --listen --no-middle                                        \
    --image="/usr/share/icons/Mint-X/status/scalable/non-starred-symbolic.svg" \
    --icon-size=24 --text="Toggle ON/OFF" --command="bash -c on_click" <&3
##################################################################################################################
# NOTES:
# This on_click function would work well, without any export and RE-exec, if this function was called from the
# main process. But here it is called from YAD, which is a child process. So this on_click function becomes part of
# this child process. At least, that's the way i understand this. And so, in this child process, the $PIPE variable
# is lost if not exported, and the exec 3<> must be re-done from within this child process, etc. This is getting
# too complicated and i just don't like it!
#
# I want to find some other way... (Fri, 02 Apr 2021 13:36:59 -0400)
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
Locked

Return to “Themes, Icons & Wallpaper”