notify-send(1) can't replace an existing notification

Bug #257135 reported by Ralph Corderoy
This bug affects 56 people
Affects Status Importance Assigned to Milestone
libnotify (Debian)
Fix Released
libnotify (Ubuntu)
Fix Released

Bug Description

Binary package hint: libnotify-bin

Ubuntu 8.04, libnotify-bin 0.4.4-3build1.

notify-send(1) is very useful but it doesn't tell me the notification ID that's been created, nor does it let me specify that to replace an earlier notification. See, in particular the replaces_id parameter and the return value.

I'd like to be able to use it something like

    id=$(notify-send --show-id foo)
    sleep 60
    notify-send --replace $id bar

This would be great for long-running shell scripts that are monitoring something.

Tags: patch
Revision history for this message
cnom (cnom) wrote :

This would me wildly useful. Something for the wish list?

Changed in libnotify (Ubuntu):
status: New → Confirmed
Revision history for this message
Ralph Corderoy (ralph-inputplus) wrote :

I consider it a bug that the underlying mechanism returns an ID and allows for its replacement yet the userspace command doesn't. It's restricting the usefulness of the mechanism.

Revision history for this message
quequotion (quequotion) wrote :

It would be really nice to have command line access to this parameter.

There are nearly as many use-cases for this as there are for using notify-send at all.
This would enable easily scripted messages to update status quickly. As it is, to get messages at the speed of channel surfing, temperature changes, bandwidth use, etc, etc, etc it's necessary to set an arbitrary, system-wide timeout of 1sec with notifyconf ("Notify-OSD Configuration" utility available from ppa) and set --expire-time < 1000. (This makes a notification which blinks in and out of existence.)

Case in point: I'm using notify-send for some scripts that change tv channels and volume. It would be unnecessarily complicated to write and compile a program to do these things, and since I am using a shell script I can't avoid waiting for one message to disappear before the next appears.

To be precise I want to do this:

notify-send --replaces_id=tvvolume --icon=gtk-info --urgency=critical --expire-time=999 "Volume" "`v4l2-ctl -C volume`

I imagine this command would set the id for the first notification to "tvvolume" and replace that with other notifications that have the same id.... Of course an implementation on par with gnome's volume indicator would be best, but before that I have another long list of feature requests.

Changed in libnotify (Ubuntu):
importance: Undecided → Low
Revision history for this message
cometdog (ericctharley) wrote :

@ Sebastien Bacher

I want to disclose up front that I really don't know the details of how bug importance is assigned, or what it really means for this to be "Low" importance.

That said, it does look like you have looked at bug #390508 (I see that you responded there), which many people have been quite vocal and upset about. In my opinion fixing this bug (#257135) in notify-send so that it can replace notifications would solve many people's problems on #390508. That is, I think it would solve the underlying issue for those who want to be able to specify a shorter timeout. With that in mind, would it be reasonable to increase the importance to something higher than "Low?" My concern is that if it is rated "Low" it may never really get worked on.

Revision history for this message
Martin Sander (forke) wrote :

hack something together in ruby/python/<insert_other_script_language_of_choice_with_dbus_support_here>.

As I have done here:
(probably not idiomatic Ruby, I know much more Python and Perl..). Maybe I will add the missing stuff so that it is fully backward-compatible to notify-send and can work as a drop in. Maybe I won't.

You can't pick the ID yourself, you have to take the one that the notification-daemon sends back via dbus. It's an INT32, so "tvvolume" won't be possible.

Revision history for this message
quequotion (quequotion) wrote :


How can you know what that number is?

Revision history for this message
Paul Collins (pjdc) wrote :

Here's a patch to notify-send.c that adds --print-id and --replace-id switches.

I've tested it lightly here and it seems to do what I expect.

Revision history for this message
Paul Collins (pjdc) wrote :

Here's v2 of the patch, which now terminates the argument list to g_object_set correctly.

Revision history for this message
Ralph Corderoy (ralph-inputplus) wrote :

Thanks Paul. Why might there not be an id to print?

Revision history for this message
Paul Collins (pjdc) wrote :

Hi Ralph,

Actually, I don't know if that can happen. And even if the ID is 0, we should print it anyway, because, as I discovered when I was updating my scripts, we can then safely write

while ...; do
    id=$(notify-send -p -r $id ...)

which is nice and simple.

Attached is v3 of the patch with the check removed.

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "notify-send.c: add --print-id and --replace-id switches" of this bug report has been identified as being a patch. The ubuntu-reviewers team has been subscribed to the bug report so that they can review the patch. In the event that this is in fact not a patch you can resolve this situation by removing the tag 'patch' from the bug report and editing the attachment so that it is not flagged as a patch. Additionally, if you are member of the ubuntu-reviewers team please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by Brian Murray. Please contact him regarding any issues with the action taken in this bug report.]

tags: added: patch
Revision history for this message
Mateo Salta (mateo-salta) wrote :

It would be nice to know how to use the patch, where notify-send.c is to be placed...

Revision history for this message
Mateo Salta (mateo-salta) wrote :

Ok, I figured it out, copy the patch text, save as "patch". download source, , un-archive the source, put "patch" in the source folder, patch with `patch -p1 < patch` in terminal in the folder, then



`sudo make install`

If that is too complipacated, someone at IZX at AskUbuntu made a ppa with the patch applied:

Changed in libnotify (Debian):
status: Unknown → New
Revision history for this message
Colin Hemming (b-ubuntuone14) wrote :

I would find this incredibly helpful, but would also love to be able to also dismiss something by ID. That way a "Processing..." notification could be displayed indefinitely, then removed when the process behind completed.

As someone seems to have already patched this it would be fantastic to see it deployed in the official repositories, rather than having to muck about compiling my own version!

Revision history for this message
sezanzeb (sezanzeb) wrote :

Yes, please deploy the patch if it works

Revision history for this message
WinEunuchs2Unix (ricklee518) wrote :

It would be nice to have the patch applied both the standard call from bash as well as the python libraries (2.7.12 and 3.x).

Revision history for this message
WinEunuchs2Unix (ricklee518) wrote :

I ended up using the answer in Ask Ubuntu:

The basic concept is you link your message to the last message you sent with an extra line:

     -h string:x-canonical-private-synchronous:anything

Where 'anything' is the string/text grouping your spamming bubbles together so fast repeating one replaces the one before (in that same group).

Code snippet from within larger while loop:

    # echo CurrVolume: $CurrVolume LastVolume: $LastVolume

    if [[ "$CurrVolume" != "$LastVolume" ]] ; then
        # Ask Ubuntu:
        notify-send --urgency=critical "tvpowered" \
            -h string:x-canonical-private-synchronous:volume \
            --icon=/usr/share/icons/gnome/48x48/devices/audio-speakers.png \
            "Volume: $CurrVolume"
        # TODO: Process VolumeCnt internally in loop instead of larger loop

    if [[ $VolumeCnt > 0 ]]; then
        (( VolumeCnt-- ))

    sleep $SleepTime

In the link comments point out how this only works in Ubuntu and not in Gnome. It works fine in Ubuntu 16.04.7 LTS with Unity desktop but I haven't tried it on other desktops yet

SleepTime of '0.01' is too small for real time but the bash script has overhead of communicating to TV over WiFi which gives it about the '0.5' seconds lag.

Revision history for this message
Paweł (telefonciek) wrote :

When could we expect this patch to be deployed?

Revision history for this message
Matthias Sweertvaegher (mx1up) wrote :

btw, I created a PR upstream. still waiting for merging though

Changed in libnotify (Debian):
status: New → Fix Released
Changed in libnotify (Ubuntu):
status: Confirmed → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libnotify - 0.7.11-1

libnotify (0.7.11-1) unstable; urgency=medium

  * New upstream release:
    - notify-send: Support for replacing an existing notification (LP: #257135,
      Closes: #559544)
    - notify-send: Support commas in icon filenames (LP: #674642)
    - notify-send: Give failing exit code if showing notification fails
      (LP: #1970647, Closes: #609556, Closes: #679653)
    - notify-send: Add support for notification actions and responses
      (Closes: #571181)
    - notify-send: Add option to wait until notification has been closed
    - notify-send: Add support for boolean hints (Closes: #636343)
    - docs/notify-send: Add missing --app-name to manpage (Closes: #756151)
  * debian/rules: Use DPKG_GENSYMBOLS_CHECK_LEVEL instead of override
  * debian: Use debhelper 13, and remove explicit --fail-missing
  * debian/control: Update Standards-Version, no change needed
  * debian/libnotify4.symbols: Add new symbols
  * debian/patches: Add transient option to man

 -- Marco Trevisan (Treviño) <email address hidden> Wed, 27 Apr 2022 21:47:25 +0200

Changed in libnotify (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.