Last active
April 17, 2024 02:40
-
-
Save RealYukiSan/7baa2fad355d18060a206951c26dadd7 to your computer and use it in GitHub Desktop.
auto shutdown on low battery
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/sh | |
threshold=10 # threshold percentage to trigger alert | |
while :; do | |
capacity=$(cat /sys/class/power_supply/BAT1/capacity) | |
# If battery is discharging with capacity below threshold | |
if [ "${capacity}" -lt ${threshold} ];then | |
# Send a notification that appears for 300000 ms (5 min) | |
notify-send -t 300000 "Charge your battery!" | |
break | |
else | |
sleep 1m | |
fi | |
done | |
# the script are modified version of this article https://ejmastnak.com/tutorials/arch/battery-alert/ |
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/sh | |
while :; do | |
batt=`cat /sys/class/power_supply/BAT0/capacity` | |
if [[ $batt -le 10 ]]; then | |
shutdown now | |
fi | |
sleep 1m | |
done |
it seems interesting to run the program on startup, maybe I need to mess up with systemd? haven't tried it before.
and watching the state of battery (charging or discharging) to resume/respawn the program on discharge, and exit/suspend/stop the program on charging
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wonder how to use other notification UI, says Telegram? so maybe I don't need to install additional package and use the telegram notification instead? is that even possible?
I see the telegram service on
/usr/share/dbus-1/services/