#!/bin/bash # 02-voice-announce.sh — speak a sentence out loud on each HearthGate event. # # Why you might want this: # You are in the kitchen, headphones off, AirPods playing music elsewhere. # A banner notification is easy to miss; the Mac speaking is not. This is # also the most demoable hook there is — friends will laugh. # # Accessibility note: # For low-vision users, this is the friendliest way to know what is # happening on the SSH side without leaving the current app. # # Setup: # Make the script executable, then add it from HearthGate's Hooks tab. # Full guide: https://codnamacs.com/hearthgate/help/features/hooks # # Customisation: # Edit the VOICE variable below — `say -v "?"` from Terminal lists every # voice your Mac has. Default is the system voice, which respects whatever # the user picked in System Settings → Accessibility → Spoken Content. # # Environment HearthGate provides: # HEARTHGATE_EVENT # HEARTHGATE_SESSION_DURATION_SEC (disconnect only) # # Test it: # HEARTHGATE_EVENT=on-connect ./02-voice-announce.sh # HEARTHGATE_EVENT=on-disconnect HEARTHGATE_SESSION_DURATION_SEC=180 ./02-voice-announce.sh set -euo pipefail EVENT="${HEARTHGATE_EVENT:-${1:-unknown}}" DURATION_SEC="${HEARTHGATE_SESSION_DURATION_SEC:-}" # Leave empty to use the system default voice. Try "Samantha", "Daniel", # "Karen", or run `say -v "?"` to see everything installed. VOICE="" speak() { local sentence="$1" if [ -n "$VOICE" ]; then say -v "$VOICE" "$sentence" else say "$sentence" fi } # Round duration to a sentence that does not sound like a robot: "two # minutes" instead of "one hundred and twenty seconds". human_duration() { local secs="$1" if [ "$secs" -lt 60 ]; then echo "$secs seconds" elif [ "$secs" -lt 120 ]; then echo "about a minute" elif [ "$secs" -lt 3600 ]; then local m=$((secs / 60)) echo "about $m minutes" else local h=$((secs / 3600)) local m=$(((secs % 3600) / 60)) if [ "$m" -eq 0 ]; then echo "about $h hours" else echo "about $h hours and $m minutes" fi fi } case "$EVENT" in on-connect|after-connect) speak "Hearth Gate. Remote session started." ;; on-disconnect|after-disconnect) if [ -n "$DURATION_SEC" ]; then speak "Hearth Gate. Session ended after $(human_duration "$DURATION_SEC")." else speak "Hearth Gate. Session ended." fi ;; *) echo "voice-announce: unrecognised event '$EVENT'" >&2 ;; esac