#!/usr/bin/env bash # alfred-notify - Send notifications and alarms to Alfred mobile app # Usage: alfred-notify [OPTIONS] MESSAGE set -euo pipefail # Configuration PROXY_URL="${ALFRED_PROXY_URL:-http://localhost:18790}" NOTIFICATION_TYPE="alert" TITLE="AI Assistant" PRIORITY="default" SOUND="true" VIBRATE="true" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Usage usage() { cat << EOF Usage: alfred-notify [OPTIONS] MESSAGE Send notifications and alarms to Alfred mobile app via proxy. OPTIONS: -a, --alarm Send as alarm (high priority, full screen) -t, --title TITLE Notification title (default: "AI Assistant") -p, --priority LEVEL Priority: low, default, high (default: default) -s, --no-sound Disable sound -v, --no-vibrate Disable vibration --user USER_ID Send only to devices for this user (OAuth sub) -u, --url URL Proxy URL (default: http://localhost:18790) -h, --help Show this help EXAMPLES: # Simple notification alfred-notify "Reminder: Check the oven" # Alarm with custom title alfred-notify --alarm --title "Wake Up!" "Time to get up" # Quiet notification alfred-notify --no-sound --no-vibrate "Silent message" # Custom proxy URL alfred-notify --url http://192.168.1.169:18790 "From remote server" ENVIRONMENT: ALFRED_PROXY_URL Override default proxy URL NOTES: - Alarms use high priority and are more intrusive - Messages sent via FCM will wake the device - Token persistence ensures delivery even after proxy restarts EOF exit 0 } # Parse arguments MESSAGE="" USER_ID="" while [[ $# -gt 0 ]]; do case $1 in -a|--alarm) NOTIFICATION_TYPE="alarm" PRIORITY="high" shift ;; -t|--title) TITLE="$2" shift 2 ;; -p|--priority) PRIORITY="$2" shift 2 ;; -s|--no-sound) SOUND="false" shift ;; -v|--no-vibrate) VIBRATE="false" shift ;; --user) USER_ID="$2" shift 2 ;; -u|--url) PROXY_URL="$2" shift 2 ;; -h|--help) usage ;; -*) echo -e "${RED}Error: Unknown option: $1${NC}" >&2 echo "Use --help for usage information" >&2 exit 1 ;; *) MESSAGE="$1" shift ;; esac done # Validate message if [[ -z "$MESSAGE" ]]; then echo -e "${RED}Error: MESSAGE is required${NC}" >&2 echo "Use: alfred-notify [OPTIONS] MESSAGE" >&2 exit 1 fi # Build JSON payload if [[ -n "$USER_ID" ]]; then JSON_PAYLOAD=$(cat <&2 echo " Make sure Alfred app is connected or FCM token is registered" >&2 exit 2 fi else echo -e "${RED}✗ Failed to send notification${NC}" >&2 echo " HTTP Status: $HTTP_CODE" >&2 echo " Response: $BODY" >&2 exit 1 fi