I have minimal draft as starting to get the solution to your problem. But it works only with Ubuntu MATE 22.04 LTS.
In my solution we need to do three steps:
mkdir -p ~/.local/share/applications
cat <<EOF | tee ~/.local/share/applications/my-toggle.desktop
2.create a script to modify desktop-file
cat <<\EOF | sudo tee /usr/local/bin/my-toggle
if grep ^Icon=mate-ax-key-no "$my_toggle_desktop"; then
sed "s|mate-ax-key-no|mate-ax-key-yes|g" -i "$my_toggle_desktop"
zenity --info --text "calling /usr/local/bin/my-connection-start"
sed "s|mate-ax-key-yes|mate-ax-key-no|g" -i "$my_toggle_desktop"
zenity --info --text "calling /usr/local/bin/my-connection-stop"
sudo chmod +x /usr/local/bin/my-toggle
3.navigate Caja to
~/.local/share/applications then double click on my-toogle for first time to mark it as trusted, then drag and drop it to MATE Panel.
On 22.04 LTS it works as expected
you can replace
zenity by actual calls to your scripts.
But here I have a question to MATE developers - how should I adapt above method to 20.04 LTS? Icon is not updating on MATE Panel here. Maybe @vkareh or @raveit65 can help?
Note: the above method works normally with MATE 1.26 from fresh-mate PPA on 20.04 LTS.