Last active
August 29, 2015 14:10
-
-
Save KlausTrainer/d9c92cec9438f2715232 to your computer and use it in GitHub Desktop.
Monitors the remaining battery capacity on a GNU/Linux system, and sends a desktop notification if the remaining capacity falls below a certain threshold.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Monitors the remaining battery capacity on a GNU/Linux system, and | |
# sends a desktop notification if the remaining capacity falls below a | |
# certain threshold. | |
WARNING_THRESHOLD=7 # percent | |
ICON="/usr/share/icons/gnome/scalable/status/battery-low-symbolic.svg" | |
CHECK_INTERVAL=60 | |
CAPACITY_REGEX="Battery 0: Discharging, (\d{1,3})%" | |
while true; do | |
remaining_capacity=$(acpi -b | perl -e "<> =~ /$CAPACITY_REGEX/ && print \${1}") | |
if [ ! -z $remaining_capacity ] && [ $remaining_capacity -le $WARNING_THRESHOLD ]; then | |
notify-send --urgency=critical "Battery Critically Low" "This computer has about ${remaining_capacity}% battery capacity remaining." --icon="$ICON" | |
fi | |
sleep $CHECK_INTERVAL | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment