Add install script for mac-agent

This commit is contained in:
2026-03-23 18:57:24 -07:00
parent 96d5a2b249
commit 80b93bdb1c
5 changed files with 99 additions and 21 deletions

48
mac-agent/install.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/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" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>$LABEL</string>
<key>ProgramArguments</key>
<array>
<string>$VENV/bin/python3</string>
<string>-u</string>
<string>$SCRIPT_DIR/kb-focus.py</string>
</array>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/kb-focus.stdout.log</string>
<key>StandardErrorPath</key>
<string>/tmp/kb-focus.stderr.log</string>
</dict>
</plist>
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"