Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am setting a notification with notify-send in a script. The only problem is that when the script is called several times, all the notifications are added to a notification stack and only called one after the other.

Is there a way to clear all notifications on the screen and display the new one ?

share|improve this question
up vote 2 down vote accepted

Unfortunately, you can not clear or "dismiss" the notify-osd notifications. You might have better luck using Zenity instead; it has more options than notify-send.

You could use the --timeout option to dismiss a notification after some number of seconds has passed.

zenity --info --timeout=5 --title="Test Notification" --text "$(date +%Y%m%d-%H%M%S): My notification"

You could also keep a list of process IDs (in an environment variable or file) of previous notifications and send them a HUP signal to clear them out before displaying a new notification.

for x in $(seq 1 5); do
    i=$((i + 1))
    zenity --info --title="Test Multiple Notifications" --text "$(date +%Y%m%d-%H%M%S): Notification number $i" &
    pids+="$! "
sleep 5
for p in $pids; do kill -HUP $p >/dev/null 2>&1; done
i=$((i + 1))
zenity --info --timeout=2 --title="Test Multiple Notifications" --text "$(date +%Y%m%d-%H%M%S): Notification number $i" &

Or kill all zenity processes before displaying a new notification:

killall zenity
zenity --info --title="Test Notifications" --text "$(date +%Y%m%d-%H%M%S): My notification" &

Or kill certain zenity processes before displaying a new notification:

ps ho pid,args | grep -i 'zenity.\+--title=test notifications' | sed -e 's/^ *\([0-9]\+\).*$/\1/'
zenity --info --title="Test Notifications" --text "$(date +%Y%m%d-%H%M%S): My notification" &
share|improve this answer
It would be unfair if I downvoted this, but you are clearly wrong. With regard to notifications, zenity has a far poorer set of options than notify-send. And it does in no way solve the problem, because it also does not give control over the notifications already sent. – jankes Nov 8 '11 at 12:11
@jankes: Sorry, I originally answered on my mobile and couldn't really elaborate my answer. Edited my answer to elaborate. – Dan Cruz Nov 8 '11 at 13:48
What you presented are information dialogs, not notifications. they can be used as a form of substitute, but are of an entirely different nature. To create notifications with zenity, you need to use the --notification option together with --listen. – jankes Nov 8 '11 at 14:10

This is actually feasible using notify-send:

notify-send --hint int:transient:1 "Title" "Body"

By setting the transient hint, the when the notification expires or dismissed, it does not linger around in the notification bar.

share|improve this answer

Unfortunately this does not seem feasible with notifications set by notify-send. Have a look at the source code of notify-send.c - it creates a notification, sets its parameters but does not store any reference to it, anywhere. Instead, it calls g_object_unref, which, as I understand from here, effectively removes the possibility of external interaction with the message. So, to have advanced management power over the notifications, you'd need to use different tool than notify-send (probably a custom application).

A possible crude hack to achieve your goal would be a script using xautomation tools. You could use them to locate the "close" buttons on all the notification pop-ups and simulate a mouse click on each of them. But that's not so easy and certainly not a neat solution.

share|improve this answer

Maybe not the best option but here's an alternative: you can simply kill the notify-osd process and restart it. Then publish your notification.

pkill notify-osd
/usr/lib/x86_64-linux-gnu/notify-osd &
notify-send "Hello!"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .