How to force a new Notification in notify-osd to show up without waiting for the earlier one to exit?
I have made a script(and a .desktop shortcut leading to this script) for starting and stoping xampp...
It checks the status of xampp and accordingly either starts or stops xampp.
Now i have assigned a notification as soon as the script is started to display "Starting xampp..." or "Stopping xampp..." and then when xampp is started or stopped,it displays "Xampp started..." or "Xampp stopped..."
I've used notify-send to show notification as seen in the script below
Now the thing is that here,the second notification waits for the 1st one to disappear and then pops up even if xampp has started/stopped.
I want the new notification to appear immediately by forcing the earlier one to exit before the completion of its life-cycle.
This can be seen to take plce when you activate/deactivate wireless/networking immediately...
For example the "Wireless enabled" comes up on selecting enable wireless and if you immediately select disable wireless,the "Wireless disabled" notification comes up without waiting for "Wireless enabled" notification to complete its life-cycle.
So how do i achieve this?
#!/bin/sh
SERVICE='proftpd'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
notify-send -i /opt/lampp/htdocs/xampp/img/logo-small.gif "Stopping XAMPP..." &&
gksudo /opt/lampp/lampp stop && notify-send -i /opt/lampp/htdocs/xampp/img/logo-
small.gif "XAMPP Stoped."
else
notify-send -i /opt/lampp/htdocs/xampp/img/logo-small.gif "Starting XAMPP..." && gksudo /opt/lampp/lampp start && notify-send -i /opt/lampp/htdocs/xampp/img/logo-small.gif "XAMPP Started."
fi
On the man page for notify-send I found --urgency=LEVEL or -u where levels are low, normal, critical.
Is this of any use? making it critical?
Also I tried it with the command- notify-send -u=critical"Testing"
but that dint work...it gives the error-
Unknown urgency criticalTesting specified. Known urgency levels: low, normal, critical.
or if I give the command notify-send -u=LOW"Testing"
it gives me error missing argument to -u
Any relation??
Information from comments,
for some reason this is working in a wierd way! it shows up a dialogue box instead of notification for the part "Starting xampp.." and "Stopping xampp.." and then shows a notification of "xampp started" or "xampp stopped"... :/ the dialogue box copes up with ok and cancel buttons!
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...
You can use notify_notification_update, followed by notify_notification_show, to update your existing notification.
Here is an example with Python and PyGObject:
from time import sleep
from gi.repository import Notify
Notify.init(app_name = 'notification-update-example')
notification = Notify.Notification.new("Notification", "Original message", None)
notification.show()
sleep(3)
notification.update("More notification", "Updated message", None)
notification.show()