Dotfiles/desktopenvs/hyprland/scripts/timer-notify.sh

48 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Background timer: sleeps, notifies, rings thrice in 30s unless dismissed
# Usage: timer-notify.sh <seconds> <label>
DURATION=${1:?missing duration}
LABEL=${2:-"00:00:00"}
sleep "$DURATION"
# Find a ring sound (freedesktop stereo sounds)
SOUND=""
for candidate in \
/usr/share/sounds/freedesktop/stereo/complete.oga \
/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga \
/usr/share/sounds/freedesktop/stereo/bell.oga \
/usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga; do
[[ -f "$candidate" ]] && { SOUND="$candidate"; break; }
done
play_sound() {
[[ -z "$SOUND" ]] && return
if command -v paplay &>/dev/null; then
paplay "$SOUND" &
elif command -v pw-play &>/dev/null; then
pw-play "$SOUND" &
fi
}
# Send notification — blocks (-w) until dismissed or timeout
# Rings play while this is waiting; kill -0 checks if it's still alive
if command -v dunstify &>/dev/null; then
dunstify -w -u critical -i alarm-clock \
-A "default,Dismiss" \
-t 30000 \
"⏱ Timer: $LABEL" "Your timer has expired." &
else
notify-send -w -u critical -i alarm-clock \
-t 30000 \
"⏱ Timer: $LABEL" "Your timer has expired." &
fi
NOTIF_PID=$!
play_sound # ring 1 — immediately
sleep 10; kill -0 "$NOTIF_PID" 2>/dev/null && play_sound # ring 2 — 10s
sleep 10; kill -0 "$NOTIF_PID" 2>/dev/null && play_sound # ring 3 — 20s
wait "$NOTIF_PID" 2>/dev/null || true