I found YAD (Yet Another Dialog) to provide the simplest solution. See webupd8 s short description. However, integration into Unity appears to be slightly broken at the moment. I mention a work-around below, but if you really care about Unity you should probably look at the other answers.
Note: While I m led to believe that YAD works in a wide range of environments, I ve only tested the instructions below using Lubuntu 15.10 (LXDE desktop) and Ubuntu 14.04 (Unity desktop).
Installation
I obtained a working installation with:
sudo apt-add-repository ppa:webupd8team/y-ppa-manager
sudo apt-get update
sudo apt-get install yad
(In fact, I didn t need the first two lines in Lubuntu 15.10, but that may have been a coincidence.)
In LXDE, calling
yad --notification --listen
then brought up a tray icon which I could change by typing (for example): icon:gtk-help
. In Unity, nothing appeared, so I needed the following ...
Work-around for Unity:
The following instructions are again taken from webupd8.
The problem is that a "system tray" does no longer officially exist in Unity. One possible solution for running programs like YAD that haven t caught up with this change is to install a "system tray emulator":
sudo apt-add-repository ppa:fixnix/indicator-systemtray-unity
sudo apt-get update
sudo apt-get install indicator-systemtray-unity
To obtain icons directly in the Unity panel, I used the following settings:
gsettings set net.launchpad.indicator.systemtray tray-is-static true
gsettings set net.launchpad.indicator.systemtray show-background-static false
Once I d log out and back in again, yad --notification
worked as expected. (Moreover, the "systemtray" displayed some additional icons that I had previously been searching in vain.) The position of the icons on the panel can be adapted via:
gsettings set net.launchpad.indicator.systemtray static-x 1500
(where 1500 may be replaced by any reasonable value). I do not know how to get the icons to be displayed flush-right. If you ever feel like uninstalling the "system tray emulator" again, webupd8 recommend:
sudo apt-get purge indicator-systemtray-unity
Demo
Here s a simplistic demo that might help illustrate how to use YAD in real-world scenarios. I m assuming YAD itself is already installed as described above. Suppose we would like to watch the output of some program running on the command line and update a tray icon accordingly. For the purposes of this demo, let s just take this "program" to be the following script "dummyprogram.sh":
#! /bin/bash
i=1
while [ $i -ne 3 ]
do
let "i=((i+1)%2)"
echo $i
sleep 1
done
Copying the above lines to a file "dummyprogram.sh", making it executable with "chmod +x dummyprogram.sh" and calling "./dummyprogram.sh" should result in the following output:
0
1
0
1
...
(one line every second). Now for the actual task at hand. To get an "iconified" version of the above output in the tray area, we use the following script "demo.sh":
#! /bin/bash
while read x
do
if [ $x -eq 0 ]
then
echo icon:gtk-home
else
echo icon:gtk-help
fi
done
Again, copy the lines to a file "demo.sh" and make it executable. Calling
./dummyprogram.sh | ./demo.sh | yad --notification --listen
should now lead to the desired result: an icon in the tray area which changes back and forth between two different icons each second.
You can end the demo by typing Ctrl-C in the terminal.