Created
January 10, 2021 05:49
-
-
Save skulltech/61080afb765feb4d328cec86f0d14aa4 to your computer and use it in GitHub Desktop.
Bash script for maintaining optimal battery charging range on a laptop
This file contains 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 | |
while true; do | |
export DISPLAY=:0.0 | |
battery_level=$(acpi -b | grep -m1 -P -o '[0-9]+(?=%)' | awk '$1>0 { print $0; }') | |
ac_power=$(acpi -a | cut -d' ' -f3 | cut -d- -f1) | |
if [ "$ac_power" = "on" ]; then | |
if [ "$battery_level" -ge 80 ]; then | |
notify-send -u critical "Please unplug your AC adapter" "Battery level: ${battery_level}%" -i battery-full-charged | |
fi | |
else | |
if [ "$battery_level" -le 30 ]; then | |
notify-send -u critical "Please plug your AC adapter" "Battery level: ${battery_level}%" -i battery-caution | |
fi | |
fi | |
sleep 60 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment