49 lines
1.3 KiB
Bash
Executable File
49 lines
1.3 KiB
Bash
Executable File
#!/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"
|