There is a patch for this bug at - https://bugs.launchpad.net/ubuntu/+source/libnotify/+bug/257135?comments=all
@izx has made a ppa version for the patch so installation is now easy (thank you izx!)- How do I use 'notify-send' to immediately replace an existing notification?
To install, open a terminal and:
sudo apt-add-repository ppa:izx/askubuntu
sudo apt-get update
sudo apt-get install libnotify-bin
Now you should have installed a patched version of notify-send that can now replace and print id numbers, so you can use just one notification box for your shell script. The program now has -p
and -r
options, or the long syntax being --print-id
and --replace-id
I wrote up a script based on your original that will make use of this, the starting and stopping notifications display until the stopped and started display, and it reuses the same notification box, if you have installed the patched version, make an file called config.txt
and put the number 0 inside, then put that file in the same folder as your lampp.sh file.
#!/bin/sh
SERVICE='proftpd'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
notify-send -t 0 -p -r `cat config.txt` -i /opt/lampp/htdocs/xampp/img/logo-small.gif "Stopping XAMPP ..." >config.txt && gksudo /opt/lampp/lampp stop && notify-send -r `cat config.txt` -t 5000 -i /opt/lampp/htdocs/xampp/img/logo-small.gif "XAMPP Stoped."
else
notify-send -t 0 -p -r `cat config.txt` -i /opt/lampp/htdocs/xampp/img/logo-small.gif "Starting XAMPP ..." >config.txt && gksudo /opt/lampp/lampp start && notify-send -r `cat config.txt` -t 5000 -i /opt/lampp/htdocs/xampp/img/logo-small.gif "XAMPP Started."
fi
Edit This is how it shows on mine...
Best Answer
We can always call notify-send as a subprocess, e.g like that:
Alternatively we could also install python-notify2 or python3-notify2 and call the notification through that: