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.

When I use notify-send to show a notification on the desktop, and then use it again to show a different notification, I have noticed that the second one only shows after the first one has disappeared.

Is there a way to get notify-send to immediately replace an existing notification with a different one?

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

You can, but you must use a patched libnotify to do so

notify-send does not have the capability to replace existing notifications before they have timed out (or disappeared). This is a known bug. However, a commenter on the bug report has posted a patch to fix it.

Installing the patched libnotify-bin from PPA

I have created a patched version of the libnotify-bin package which allows replacements in my PPA. Currently it's for Ubuntu 12.04 only, but if you need it for any other currently supported release, please post a comment and I will try my best to make it available.

To install, open a terminal and:

sudo apt-add-repository ppa:izx/askubuntu
sudo apt-get update
sudo apt-get install libnotify-bin

How to use the replacement capabilities

The patched notify-send includes two new switches, -p (or --print-id ), and -r (or --replace-id ). The --help describes them as:

  -p, --print-id                    Print the notification ID.
  -r, --replace-id=REPLACE_ID       The ID of the notification to replace.
  • With -p, each notify-send will return an ID N (number/integer).
  • Issuing another notify-send with -r N will replace the previous notification immediately.
  • For example, for bash, you can save the ID from notify-send -p ... with:

    NID=$(notify-send -p "MESSAGE-1")
    

    and then replace it with:

    notify-send -r $NID "MESSAGE-2"
    
  • You can recursively use both -p and -r in a script, as long as the -r variable is initialized to 0 at the beginning.

  • Here's a simple script that shows notifications counting from 0 to 100 at half-second intervals:

    #!/bin/bash
    NID=0
    for i in {0..100..10}    do       NID=$(notify-send -p -r $NID $i)       sleep 0.5    done
share|improve this answer
add comment

X-ref:
How to force a new Notification in notify-osd to show up without waiting for the earlier one to exit?

without patches you can simply do

#!/bin/bash

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

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


Sends an error notify-osd(2592): Operation not permitted. What does that mean?

It may mean that privileges are inadequate requiring:

sudo killall notify-osd
share|improve this answer
    
Sends an error notify-osd(2592): Operation not permitted. What does that mean? –  VedVals Nov 12 '12 at 18:22
add comment

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.