#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="${PROJECT_DIR:-$SCRIPT_DIR}" TARGET_DIR="$HOME/Library/LaunchAgents" PLIST_NAME="com.maddin.whisper-transcript-pipeline.plist" TARGET_PLIST="$TARGET_DIR/$PLIST_NAME" DOMAIN="gui/$(id -u)" LABEL="com.maddin.whisper-transcript-pipeline" PYTHON_BIN="${PYTHON_BIN:-$(command -v python3 || true)}" if [[ -z "$PYTHON_BIN" ]]; then echo "python3 not found in PATH" >&2 exit 1 fi mkdir -p "$TARGET_DIR" cat >"$TARGET_PLIST" < Label $LABEL ProgramArguments $PYTHON_BIN $PROJECT_DIR/transcript_pipeline.py watch WorkingDirectory $PROJECT_DIR RunAtLoad KeepAlive EnvironmentVariables PATH $HOME/bin:$HOME/.local/bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin PYTHONUNBUFFERED 1 StandardOutPath $PROJECT_DIR/launchd.stdout.log StandardErrorPath $PROJECT_DIR/launchd.stderr.log EOF launchctl bootout "$DOMAIN" "$TARGET_PLIST" >/dev/null 2>&1 || true launchctl bootstrap "$DOMAIN" "$TARGET_PLIST" launchctl enable "$DOMAIN/$LABEL" launchctl kickstart -k "$DOMAIN/$LABEL" echo "Installed and started $LABEL"