15

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
Jacob Vlijm
  • 85,475
evamvid
  • 255

4 Answers4

13

Alternatively, if you do not want the notification to show up in the notification history at all, you can try:

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

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$)
Jacob Vlijm
  • 85,475
0

I am using Mint MATE 17 The process is listed (example) 15107 ? Sl 0:00 /usr/lib/mate-notification-daemon/mate-notification-daemon

I tried pkill as $ pkill mate-notification-daemon and even $ pkill mate-notification And did not work. However, if I truncated the 'notification' word, it worked: $ pkill mate-notificati Adding the 'on' to the word makes it not work. Don't know why. I imagine this would pertain to Ubuntu MATE editions as well.

Dr_Bunsen
  • 4,783
0

For xfce desktop(Lubuntu 18.04) notify-send:

pkill xfce4-notifyd