Created
October 25, 2017 14:09
-
-
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%
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 | |
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://drive.google.com/file/d/0BwFhcg1_acLiaFhfSE5lV2pMVTQ/view?usp=sharing
tone created by @netoguimaraes