Ubuntu – Is it possible to cancel or clear a notification created by using notify-send

bashnotificationnotify-osdnotify-sendscripts

So I wrote a little script that makes sure a certain user plugs in a laptop when he logs on (it disables if he doesn't). The script uses notify-send to tell him to plug it in. If he plugs it in, the script quits. Is it possible to clear the notification automatically when he plugs it in? I'm thinking it might require somehow getting the process id spawned by notify-send and killing that PID, but I don't know how to do this.

Here's the current script:

#!/bin/bash 

cat /sys/class/power_supply/BAT0/status
OUTPUT="$(cat /sys/class/power_supply/BAT0/status)"
echo "${OUTPUT}"
if [ "${OUTPUT}" = "Charging" ] || [ "${OUTPUT}" = "Unknown" ]; then
    echo charging or full
elif [ "${OUTPUT}" = "Discharging" ]; then
    notify-send -i /home/evamvid/Documents/Programming/OokiNoUse/power25.png "Hey there brother" "plug it in"
    COUNTER=0
while [ "$COUNTER" -le 12 ]
do
    cat /sys/class/power_supply/BAT0/status
    OUTPUT="$(cat /sys/class/power_supply/BAT0/status)"
    echo "${OUTPUT}"
    if [ "${OUTPUT}" = "Charging" ] || [ "${OUTPUT}" = "Unknown" ]; then
        exit
    elif [ "${OUTPUT}" = "Discharging" ]; then
        COUNTER=$(($COUNTER+1))
        echo $COUNTER
        sleep 1
    fi
done
fi

Best Answer

The process you are looking for is notify-osd. You can kill it by either the command:

pkill notify-osd

or by its pid:

kill $(ps -e | grep notify-osd | awk '{ print $1 }')

or, even better, as suggested by @kos (thanks!), using pgrep:

kill $(pgrep ^notify-osd$)
Related Question