Last active
October 9, 2023 16:33
-
-
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.
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
#!/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