Skip to content

Instantly share code, notes, and snippets.

@nmoran
Created August 26, 2016 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmoran/208b78a45f95f9a219fb4fb35b091cd2 to your computer and use it in GitHub Desktop.
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.
#!/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