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.
i=0
pids=
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+="$! "
done
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" &
@DanCruz It's working, but I get this error: "** (zenity:8624): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged." – Dr.jacky – 2017-03-11T11:47:55.433
It would be unfair if I downvoted this, but you are clearly wrong. With regard to notifications,
– jankes – 2011-11-08T12:11:49.093zenity
has a far poorer set of options thannotify-send
. And it does in no way solve the problem, because it also does not give control over the notifications already sent.@jankes: Sorry, I originally answered on my mobile and couldn't really elaborate my answer. Edited my answer to elaborate. – Dan Cruz – 2011-11-08T13:48:48.903
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 – 2011-11-08T14:10:36.903