Created
August 26, 2016 20:58
-
-
Save nmoran/208b78a45f95f9a219fb4fb35b091cd2 to your computer and use it in GitHub Desktop.
Quick bash script to check battery status from acpi command and alert using using zenity.
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/bash | |
warn_on=20 | |
debug=0 | |
discharging=`acpi | grep Discharging | wc -l` # will be 1 if discharging and 0 if chargin | |
if [ $discharging -eq 1 ]; then # if discharging, check percentage | |
percentage_remaining=`acpi | grep -o [0-9]*% | sed s/%//g` | |
echo "Remaining ${percentage_remaining}" | |
if [ $percentage_remaining -lt $warn_on ]; then | |
DISPLAY=:0 zenity --notification --text "Warning, battery is discharging and at ${percentage_remaining}%!" | |
elif [ $debug -eq 1 ]; then | |
DISPLAY=:0 zenity --notification --text "Battery is discharging, but at ${percentage_remaining}% so it's grand!" | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment