How to clear balloon popup from bash

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.


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" &

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!"