Last active
April 29, 2020 19:31
-
-
Save wookietreiber/0e4018b840b66e4f3eb646e40fd74c8d to your computer and use it in GitHub Desktop.
battery notification
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
[Unit] | |
Description=battery notification | |
[Service] | |
Environment="DISPLAY=:0" | |
ExecStart=/bin/bash /path/to/battery-notification.sh 20 10 | |
Type=oneshot | |
[Install] | |
WantedBy=default.target |
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 | |
app=$(basename "$0" .sh) | |
[[ $# -eq 2 ]] || { | |
echo "usage: $app warning critical" >&2 | |
exit 1 | |
} | |
warning=$1 | |
critical=$2 | |
function notify { | |
notify-send -c device -i battery "$@" | |
} | |
for battery_path in /sys/class/power_supply/BAT* | |
do | |
battery=$(basename "$battery_path") | |
capacity=$(< "$battery_path/capacity") | |
if [[ $capacity -le $critical ]] | |
then | |
notify -u critical 'Battery CRITICAL' "Capacity $capacity%" | |
elif [[ $capacity -le $warning ]] | |
then | |
notify -u normal 'Battery WARNING' "Capacity $capacity%" | |
else | |
echo "OK $battery $capacity" | |
fi | |
done |
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
[Unit] | |
Description=run battery-notification | |
[Timer] | |
OnBootSec=1min | |
OnUnitActiveSec=1min | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment