-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·61 lines (53 loc) · 2.29 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·61 lines (53 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# sorting-hat installer (macOS).
# Usage: ./install.sh "<base_dir>"
# e.g.: ./install.sh "$HOME/Library/Mobile Documents/com~apple~CloudDocs/Filing"
set -euo pipefail
BASE="${1:?usage: ./install.sh <base_dir>}"
REPO="$(cd "$(dirname "$0")" && pwd)"
LABEL="com.sorting-hat.watch"
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
# --- Python: prefer Homebrew (macOS blocks the CLT python from reading
# --- iCloud/Documents when run via launchd; the Homebrew one gets a
# --- normal permission prompt you can accept once).
PY="$(command -v /opt/homebrew/bin/python3 || command -v /usr/local/bin/python3 || command -v python3)"
echo "python: $PY"
command -v claude >/dev/null || { echo "claude CLI not found — install Claude Code first"; exit 1; }
# --- folders + config
mkdir -p "$BASE/_inbox" "$BASE/_review" "$HOME/.config/sorting-hat"
[ -f "$BASE/sorting-hat-config.md" ] || cp "$REPO/config.example.md" "$BASE/sorting-hat-config.md"
# --- launchd agent: fires on every change in _inbox + daily fallback.
# --- Built with plistlib so paths with &, quotes etc. can't break the XML.
PLIST="$PLIST" PY="$PY" REPO="$REPO" BASE="$BASE" LABEL="$LABEL" \
CLAUDE_BIN="$(command -v claude)" "$PY" - <<'PYEOF'
import os
import plistlib
e = os.environ
plist = {
"Label": e["LABEL"],
"ProgramArguments": [
e["PY"], f"{e['REPO']}/sorting_hat.py", e["BASE"],
"--claude", e["CLAUDE_BIN"],
],
"WatchPaths": [f"{e['BASE']}/_inbox"],
"StartCalendarInterval": {"Hour": 9, "Minute": 30},
"RunAtLoad": True,
"ThrottleInterval": 60,
"StandardOutPath": f"{e['HOME']}/.config/sorting-hat/run.log",
"StandardErrorPath": f"{e['HOME']}/.config/sorting-hat/run.log",
}
with open(e["PLIST"], "wb") as f:
plistlib.dump(plist, f)
PYEOF
launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$PLIST"
echo
echo "sorting-hat is live."
echo " inbox: $BASE/_inbox"
echo " config: $BASE/sorting-hat-config.md (edit entities/categories!)"
echo " log: $BASE/sorting-hat-log.md"
echo
echo "Drop a scan into the inbox to test. If nothing happens, check"
echo "$HOME/.config/sorting-hat/run.log — a PermissionError means macOS"
echo "blocked folder access: grant it in System Settings → Privacy & Security,"
echo "or see the TCC section in the README."