7

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
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$)
  • It's working in a new Terminal instance, so I guess that somehow the former is corrupted, altough I can't see how! Anyway nevermind, I don't want to clutter your post further, I'll remove my comments (upvoted you answer of course) – kos Jun 23 '15 at 6:41
  • @kos I did have an odd thing btw. I even removed the answer at first because I got the message "I didn't have permission" (although it worked...) after a restart it worked fine. – Jacob Vlijm Jun 23 '15 at 6:45
  • @kos WOuld you mind if I borrowed your pgrep? option? Is actually better... – Jacob Vlijm Jun 23 '15 at 6:46
  • Not at all, go ahead :) yes I've got the same message at first but I it was when I wrongly killed fsnotify_mark instead, perhaps you were testing using [...] | grep notify | [...]? – kos Jun 23 '15 at 6:50
  • 2
    For me, using xfce, the process was not named notify-osd but instead xfce4-notifyd, more specifically /usr/lib/x86_64-linux-gnu/xfce4/notifyd/xfce4-notifyd. I could instead do pkill xfce4-notifyd and it would kill the existing notification. The next time notify-send ran, it auto created the xfce4-notifyd process again, so it seemed safe. – Scott Aug 15 '16 at 18:39
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.

0

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.