Created
May 2, 2023 13:53
-
-
Save WinkelCode/3c87dfc2a96d0263a03d240c8bb8786d to your computer and use it in GitHub Desktop.
Put in `~/.config/systemd/user/user-battery-notify.service`, enable with `systemctl --user enable --now user-battery-notify.service`. Change variables as required for your system.
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
[Unit] | |
Description=Battery Level Notifier | |
[Service] | |
Environment=BATT_PATH=/sys/class/power_supply/BAT1/capacity | |
Environment=MIN_BATT_PCT=35 | |
Environment=BATT_REFRESH_SECS=5 | |
ExecStart=bash -c 'set -e; snooze=false; while true; do [ "$(cat "${BATT_PATH}")" -le "${MIN_BATT_PCT}" ] && [ "$snooze" != "true" ] && { notify-send --urgency=critical "Battery is at or below ${MIN_BATT_PCT}%"; snooze=true; }; [ "$(cat "${BATT_PATH}")" -gt "${MIN_BATT_PCT}" ] && [ "$snooze" == "true" ] && snooze=false; sleep "${BATT_REFRESH_SECS}"; done' | |
Restart=always | |
[Install] | |
WantedBy=graphical-session.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment