#!/bin/bash # One-command Flow rinse launcher (macOS). Not headless — Brave must be logged in — # but fully unattended once the tab is open and Auto-start is ticked in the popup. # # ./launch.sh https://labs.google/fx/tools/flow/project/XXXXXXXX # FLOW_URL=... ./launch.sh # # Does three things: start the queue server if it's down, keep the Mac awake, and # open OR focus a single Flow tab in Brave (never spawns duplicates). # # Scheduled every 10 min via launchd for self-healing (see install.sh). # NOTE: launchd can't execute scripts inside ~/Documents (macOS TCC blocks it), # so the agent runs a COPY at "~/Library/Application Support/flowrinse/" — # after editing this file or local_server_example.py, re-run ./install.sh to resync. set -e DIR="$(cd "$(dirname "$0")" && pwd)" URL="${1:-$FLOW_URL}" if [ -z "$URL" ]; then echo "Usage: ./launch.sh (or set FLOW_URL)" exit 1 fi # 1. queue server on 8017 (nc check avoids consuming a task via /next-task) if ! nc -z localhost 8017 2>/dev/null; then ( cd "$DIR" && caffeinate -s python3 -B local_server_example.py >/tmp/flowrinse.log 2>&1 & ) echo "started queue server + caffeinate (log: /tmp/flowrinse.log)" sleep 1 else echo "queue server already up on 8017" fi # 2. open or focus ONE Flow tab (reuses an existing one so it can't double-run). # Only `activate` (steal system focus) when opening fresh — on the 10-min launchd # tick an existing tab is re-selected inside the browser without yanking you out of # whatever you're doing. Selecting the tab also keeps Memory Saver from discarding it. # # Must name the browser the EXTENSION is loaded into. ultra = Brave, m3ultra = Chrome. BROWSER="${FLOW_BROWSER:-Brave Browser}" # A LOCKED SCREEN wedges every AppleScript window/tab query for ~2 min, then -1712 # "AppleEvent timed out". Not a browser bug: with the screen locked, Finder, System Events # and Brave all hang on `count of windows` identically. Bail out loudly instead. if ioreg -n Root -d1 -r | tr -d ' ' | grep -q '"CGSSessionScreenIsLocked"=Yes'; then echo "screen is LOCKED on $(hostname -s) — cannot drive $BROWSER (every window query would" \ "hang, then -1712). Unlock it; for an unattended rig also set System Settings >" \ "Lock Screen > 'Require password after screen saver begins' = Never." exit 0 # not an error: the 10-min tick retries once someone unlocks fi # `open location` hands the URL to the DEFAULT browser (Brave here) — never to $BROWSER. # Make the tab inside the target app instead. Timeout so a wedged app can't hold the job. osascript <