4

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

Mateo
  • 8,104
Nirmik
  • 7,868
  • For edit 2 it looks like the syntax is notify-send -u low "Testing" – Mateo Jul 09 '12 at 19:32
  • @mateo_salta...okay thats correct...but unfortunately this method is of no use..:( – Nirmik Jul 09 '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 09 '12 at 20:12
  • @mateo_salta...its the exact script...n its workin!umm...its the script u only gave me in this answer-http://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 09 '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 09 '12 at 20:21
  • @mateo_salta....script edited to correct one – Nirmik Jul 09 '12 at 20:25
  • looks like a bug, https://bugs.launchpad.net/ubuntu/+source/libnotify/+bug/257135 – Mateo Jul 09 '12 at 20:45

3 Answers3

4

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

Mateo
  • 8,104
  • 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
  • and they are in my home folder itself...only the launher is in /usr/local/share/applications...where its supposed to be... – Nirmik Jul 13 '12 at 20:24
  • here is a screenshot of the dialogue box that comes up- http://i.stack.imgur.com/RaW4P.png..........and then comes up the password window like this-http://i.stack.imgur.com/DUMt2.png – Nirmik Jul 13 '12 at 20:33
  • and for some reason the launcher is not working at all...all this happens when i mannually run the sh file....here is the link to pastebin of the launcher file- http://pastebin.com/KzXHmup9 – Nirmik Jul 13 '12 at 20:43
  • that is because you mixed the two types of launchers from the answer in your previous question, either you have the start/stop function from the script, Or the right click menu – Mateo Jul 13 '12 at 22:56
  • oh, Unity-3D is what you are using. – Mateo Jul 13 '12 at 22:59
  • try changing the -t 0 values to something else like -t 20000 I think it is interpreting it differently than the other desktops. – Mateo Jul 13 '12 at 23:07
2

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()
Dylan McCall
  • 4,189
  • ummm....any easier way to understand that :{ – Nirmik Jul 09 '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 09 '12 at 18:53
0

X-ref:
How do I use 'notify-send' to immediately replace an existing notification?

without patches you can simply do

#!/bin/bash

for i in {0..100..10}
    do
          killall notify-osd
          notify-send "testing" $i
          sleep 0.5
    done

Bookmarks:
How to force a new Notification in notify-osd to show up without waiting for the earlier one to exit?
How do I use 'notify-send' to immediately replace an existing notification?