Posts

Showing posts from June, 2019

Notifying When Battery is Full in Linux

Image
Case: I want to be notified by a sounding popup when the battery of my laptop is fully charged. I'm using Debian Linux and Gnome 3 . Requisites: The following applications are installed: sh, upower, paplay, notify-send. Steps: Open a text editor and put this code (adapted from here ): #!/usr/bin/env bash while true do export DISPLAY=:0.0 battery_percent=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -P -o 'percentage: [0-9]+(?=%)' | grep -P -o [0-9]*) if on_ac_power; then echo $on_ac_power if [ "$battery_percent" -gt 92 ]; then paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga notify-send --urgency CRITICAL "Battery full" "Level: ${battery_percent}% " fi fi sleep 60 # done Save the file with .sh extension in the user's home directory, choice an understandable name, for example: /home/ronald/BatteryCharged.sh ...