Skip to content

Instantly share code, notes, and snippets.

@tunalad
Last active October 9, 2023 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tunalad/598856561d9f0ec502e43bf47652c571 to your computer and use it in GitHub Desktop.
Save tunalad/598856561d9f0ec502e43bf47652c571 to your computer and use it in GitHub Desktop.
Simple battery notification system using `dunst` for local notifications, and ntfy for mobile push notification. Create a cronjob that will run this script.
#!/usr/bin/bash
DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export XDG_RUNTIME_DIR="/run/user/1000"
HOSTNAME=$(uname -n)
NTFY_TOPIC="your notify.sh topic here"
acpi -b | awk -F'[,%]' '{print $2, $4, $5}' | {
read -r capacity timeleft status
[ "$capacity" -lt 25 ] && [ "$status" = "remaining" ] && {
dunstify -r 9993 -t 10000 -u critical "Battery low" "$capacity% of battery left.\nTime left: $timeleft."
curl \
-H "Title: [$HOSTNAME] Battery low" \
-H "Priority: urgent" \
-H "Tags: rotating_light" \
-d "$capacity% of battery left. Time left: $timeleft." ntfy.sh/$NTFY_TOPIC
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment