Skip to content

Instantly share code, notes, and snippets.

@StefanYohansson
Created October 25, 2017 14:09
Show Gist options
  • Select an option

  • Save StefanYohansson/4ed0ce32d1a93f5de41f762c8ba04dd4 to your computer and use it in GitHub Desktop.

Select an option

Save StefanYohansson/4ed0ce32d1a93f5de41f762c8ba04dd4 to your computer and use it in GitHub Desktop.
Battery life script to warn when battery is under 40% and above 80%
#!/bin/bash
MIN=40
MAX=80
while true ; do
unplugged=$(cat /sys/bus/acpi/drivers/battery/*/power_supply/BAT?/status|grep -i discharging)
acpiout=$(acpi)
if [ "$(echo $acpiout|grep -Po "[0-9]+(?=%)")" -le $MIN ]; then #Battery under low limit
if [ ! "$unplugged" == "" ]; then #unplugged
notify-send "Battery under $MIN percent. Please plug in the adapter"
play -q --volume 3 /home/snotr/Untitled.ogg
fi
elif [ "$(echo $acpiout|grep -Po "[0-9]+(?=%)")" -ge $MAX ]; then #Battery over high limit
if [ "$unplugged" == "" ]; then #plugged
notify-send "Battery above $MAX percent. Please remove the adapter"
play -q --volume 3 /home/snotr/Untitled.ogg
fi
fi
sleep 10 #Repeat every 10 seconds
done
@StefanYohansson
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment