Skip to content

Instantly share code, notes, and snippets.

@WinkelCode
Created May 2, 2023 13:53
Show Gist options
  • Save WinkelCode/3c87dfc2a96d0263a03d240c8bb8786d to your computer and use it in GitHub Desktop.
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.
[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