Last active
February 3, 2022 18:27
-
-
Save ComradeCat24/0b9d8dc27ad9a9b3df9c136ce74cc466 to your computer and use it in GitHub Desktop.
Get Battery notification on Linux
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=`cat /sys/class/power_supply/BAT0/capacity` | |
if [ $(cat /sys/class/power_supply/BAT0/status) = 'Charging' ]; then | |
if [ $battery_level -ge 80 ]; then | |
notify-send -t 10000 "Battery Full" "Level: ${battery_level}%" | |
fi | |
else | |
if [ $battery_level -le 25 ]; then | |
notify-send -t 10000 --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%" | |
fi | |
fi | |
sleep 60 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment