Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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!

enter image description here

share|improve this question
    
For edit 2 it looks like the syntax is notify-send -u low "Testing" –  Mateo_ Jul 9 '12 at 19:32
    
@mateo_salta...okay thats correct...but unfortunately this method is of no use..:( –  Nirmik Jul 9 '12 at 19:36
    
there are errors in your script, is this the exact copy of the script you are using, or are those just typos? –  Mateo_ Jul 9 '12 at 20:12
    
@mateo_salta...its the exact script...n its workin!umm...its the script u only gave me in this answer-askubuntu.com/a/157678/46000...i only added the earlier notifiction...and in that script u mistakenly have given stop in place of start and start in place of stop...so exchanged that –  Nirmik Jul 9 '12 at 20:16
1  
@mateo_salta....okay hold on...the ">" things seen before gksudo are the blockquotes for editing here on askubuntu for that box...its not there in the script....i'll remove that wait... –  Nirmik Jul 9 '12 at 20:21

3 Answers 3

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... enter image description here

share|improve this answer
    
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! –  Nirmik Jul 11 '12 at 18:41
    
And also its not working with the desktop shortcut/launcher...nothing happens when the shortcut is clicked –  Nirmik Jul 11 '12 at 18:50
    
dialog box? that is strange, what desktop are you using so I can try and reproduce your results. –  Mateo_ Jul 11 '12 at 19:06
    
m using unity... –  Nirmik Jul 11 '12 at 19:56
    
oh no! i know this is ought to come up...as i mentioned earlier...the dialogue box says starting xampp...then this comes up... –  Nirmik Jul 13 '12 at 20:23

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()
share|improve this answer
    
ummm....any easier way to understand that :{ –  Nirmik Jul 9 '12 at 18:47
1  
Oh, is this a shell script with notify-send? If it is, we should update your question to mention that. Including your script - or something like it - would also really help, if that is possible. Unfortunately, I don't believe this is possible (within reason) with a shell script. –  Dylan McCall Jul 9 '12 at 18:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.