Skip to content

Instantly share code, notes, and snippets.

@p0358
Created May 3, 2025 12:25
Show Gist options
  • Save p0358/fb93e218e910f66a1d5d59ce5dd08f37 to your computer and use it in GitHub Desktop.
Save p0358/fb93e218e910f66a1d5d59ce5dd08f37 to your computer and use it in GitHub Desktop.
Get desktop notifications about apcupsd events on Linux (like you would on Windows with the tray app)
# ~/.config/systemd/user/apcupsd-notify.service
# $ systemctl --user daemon-reload
# $ systemctl --user enable --now apcupsd-notify
[Unit]
Description=apcupsd notify
ConditionPathExists=/var/log/apcupsd.events
[Service]
Type=simple
ExecStart=%h/bin/apcupsd-notify.sh
Restart=always
[Install]
WantedBy=graphical-session.target
#!/bin/bash
f="/var/log/apcupsd.events"
curr=$(<"$f")
inotifywait -m -e modify "$f" --format "%e" | while read -r event; do
if [ "$event" == "MODIFY" ]; then
prev="$curr"
curr=$(<"$f")
[ "$curr" == "$prev" ] || notify-send -u critical -a apcupsd "${curr##*$'\n'}" && echo "${curr##*$'\n'}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment