I found YAD (another dialog) to provide the simplest solution. See brief description of webupd8 . However, integration in Unity seems to be a bit broken right now. I mention this below, but if you really care about Unity, you should probably look at other answers.
Note. Although I am convinced that YAD works in a wide variety of environments, I only tested the instructions below using Lubuntu 15.10 (LXDE desktop) and Ubuntu 14.04 (Unity desktop).
Installation
I got a working installation with:
sudo apt-add-repository ppa:webupd8team/y-ppa-manager sudo apt-get update sudo apt-get install yad
(Actually, I don't need the first two lines in Lubuntu 15.10, but that could be a coincidence.)
LXDE is called
yad --notification --listen
then raised the tray icon, which I could change by typing (for example): icon:gtk-help . Unity didnβt appear, so I needed the following ...
Work for Unity: The following instructions are again taken from webupd8 . The problem is that the "system tray" no longer exists officially in Unity. One of the possible solutions for launching programs such as YAD, which did not catch up with this change, is to install an "emulator in the system tray":
sudo apt-add-repository ppa:fixnix/indicator-systemtray-unity sudo apt-get update sudo apt-get install indicator-systemtray-unity
To get the 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
As soon as I yad --notification out and yad --notification again, yad --notification worked as expected. (Moreover, "systemtray" displayed some additional icons that I previously searched in vain.) The position of the icons on the panel can be adjusted using:
gsettings set net.launchpad.indicator.systemtray static-x 1500
(where 1500 can be replaced with any reasonable value). I do not know how to get the icons that will be displayed right-to-right. If you ever wanted to remove the system tray emulator, webupd8 is recommended:
sudo apt-get purge indicator-systemtray-unity
Demo
Here is a simplified demo that can help illustrate how to use YAD in real-world scenarios. I assume that YAD itself is already installed as described above. Suppose we would like to monitor the output of a program running on the command line and update the tray icon accordingly. For the purposes of this demonstration, let's just take this "program" into 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 the file "dummyprogram.sh", which makes it executable using "chmod + x dummyprogram.sh", and calling "./dummyprogram.sh" should lead to the following output:
0 1 0 1 ...
(one line every second). Now for the real problem. To get the "designated" 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
Copy the lines again to the file "demo.sh" and make it executable. Call
./dummyprogram.sh | ./demo.sh | yad --notification --listen
Now it should lead to the desired result: the icon in the tray area, which changes back and forth between two different icons every second.
You can end the demo by typing Ctrl-C in the terminal.