Last active
January 9, 2025 03:59
-
-
Save imme5150/2acc71214d56a2a6aa2f5f89999daf59 to your computer and use it in GitHub Desktop.
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_CHARGE_LEVEL=${1:-40} | |
MAX_CHARGE_LEVEL=${2:-60} | |
while true | |
do | |
battery_level=`cat /sys/class/power_supply/BAT0/capacity` | |
if [ ! $battery_level ]; then | |
echo 'No battery found' | |
exit | |
else | |
status=`cat /sys/class/power_supply/BAT0/status` | |
if [ $status == "Charging" ] && [ $battery_level -ge $MIN_CHARGE_LEVEL ]; then | |
notify-send "Battery above ${MIN_CHARGE_LEVEL}%" "Charging: ${battery_level}%" | |
elif [ $status != "Charging" ] && [ $battery_level -le $MAX_CHARGE_LEVEL ]; then | |
notify-send "Laptop UNPLUGGED" "Charge: ${battery_level}%" | |
fi | |
fi | |
sleep 60 # seconds | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment