Skip to content

Instantly share code, notes, and snippets.

@shaposhnikoff
Created December 1, 2016 16:39
Show Gist options
  • Select an option

  • Save shaposhnikoff/e2025a7b4e234e74fb2bf8915b2e61d0 to your computer and use it in GitHub Desktop.

Select an option

Save shaposhnikoff/e2025a7b4e234e74fb2bf8915b2e61d0 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -e /sys/class/power_supply/BAT0 ]; then
zenity --warning --text "STARTED MONITORING BATERY"
while true;do
CAPACITY=$( cat /sys/class/power_supply/BAT0/uevent | grep -i capacity | cut -d'=' -f2|head -1 )
case $CAPACITY in
[0-9]|11)
STATUS=$( cat /sys/class/power_supply/BAT0/uevent | grep -i status | cut -d'=' -f2 | head -1)
if [ $(echo $STATUS) == "Discharging" ]; then
# notify-send --urgency=critical --icon=dialog-warning "LOW BATTERY! SUSPENDING IN 30 sec"
zenity --warning --text "LOW BATTERY! SUSPENDING IN 30 sec"
sleep 30
gnome-screensaver-command -l && sudo pm-suspend
break
fi
;;
*)
sleep 1
continue
;;
esac
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment