configfiles/scripts/.config/scripts/batteryobserver.sh
2015-10-08 10:31:53 +02:00

33 lines
850 B
Bash
Executable file

#!/bin/bash
#Config
WARNING_LEVEL=10
SHUTDOWN_LEVEL=2
#End config
STATE=0
while true; do
level=$(acpi -b | awk -F, 'BEGIN{s=0}{s+=$2}END{print int(s/NR)}')
charger_connected=$(acpi -b | grep Charging)
case "$STATE" in
0) # battery ok
if [ "$level" -le "$WARNING_LEVEL" -a -z "$charger_connected" ]; then
zenity --warning --text="Your battery is getting low\!" --no-wrap &
STATE=1
fi
;;
1) # battery low
if [ -n "$charger_connected" ]; then
STATE=0
elif [ "$level" -le "$SHUTDOWN_LEVEL" ]; then
systemctl hibernate;
else
notify-send -u critical -a "BatterySystem" "Battery is low!" "Please connect a charger"
fi
;;
esac
sleep 2m
done