How can I get an on-screen notification using notify-osd when I plug/unplug the charger?
Ubuntu – How to get a notification using Notify-OSD when the charger is inserted/removed
batterynotificationnotify-osd
Related Question
- Ubuntu – Notify-osd and libnotify: how do they cooperate
- Ubuntu – Gnome 3 notifications are replaced with notify-osd when the machine goes to sleep
- Ubuntu – Xfce4 overrode the GNOME notifications (notify-osd). How to get them back
- Ubuntu – How to make Firefox use native notification (notify-osd)
- Ubuntu – Disable gnome-software’s notification bubble (notify-osd) for available updates
Best Answer
dbus
Some people reported my earlier udev solution sent the notification too many times when the power cable was plugged in. I couldn't reproduce that but I wrote this python script to utilize dbus instead of udev. Save it as a
.py
file somewhere on your hard drive. Mark the file executable by running:and add it to your startup applications as described here. This script requires the package
acpi
be installed.udev
With a little experimentation (and a little help) I was able to utilize a udev rule to accomplish this. Some people have reported that it sometimes sends the notification more than once but I have not had any problems. YMMV.
Create a script with the following contents:
replacing
some_user
with your username. Mark the file executable by running:replacing
/path/to/script.sh
with the path to where you saved the script.Next create a file in
/etc/udev/rules.d
named10-power.rules
with the contents:again replacing
/path/to/script.sh
with the path to the script you created earlier.Now reload the udev rules by running:
Unplug the power cable. You should get a notification.