#!/bin/bash set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" LABEL="com.user.kb-focus" PLIST="$HOME/Library/LaunchAgents/$LABEL.plist" VENV="$SCRIPT_DIR/.venv" # Create venv and install dependencies if [ ! -d "$VENV" ]; then echo "Creating virtualenv..." python3 -m venv "$VENV" fi echo "Installing dependencies..." "$VENV/bin/pip" install -q -r "$SCRIPT_DIR/requirements.txt" # Unload existing agent if present launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true # Generate plist with correct paths cat > "$PLIST" < Label $LABEL ProgramArguments $VENV/bin/python3 -u $SCRIPT_DIR/kb-focus.py KeepAlive StandardOutPath /tmp/kb-focus.stdout.log StandardErrorPath /tmp/kb-focus.stderr.log EOF # Load agent launchctl bootstrap "gui/$(id -u)" "$PLIST" echo "Installed and started $LABEL" echo "Logs: /tmp/kb-focus.stdout.log, /tmp/kb-focus.stderr.log"