-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·293 lines (259 loc) · 8.3 KB
/
setup.sh
File metadata and controls
executable file
·293 lines (259 loc) · 8.3 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env bash
set -euo pipefail
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
ok() { echo -e "${GREEN}✓${NC} $*"; }
warn() { echo -e "${YELLOW}!${NC} $*"; }
fail() { echo -e "${RED}✗${NC} $*"; }
info() { echo -e " $*"; }
step() { echo -e "\n${BLUE}$*${NC}"; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODE="${1:-setup}"
OPEN_SETTINGS=false
INSTALL_OMNIPARSER=false
START_OMNIPARSER=false
for arg in "$@"; do
case "$arg" in
--doctor) MODE="doctor" ;;
--open-settings) OPEN_SETTINGS=true ;;
--install-omniparser) INSTALL_OMNIPARSER=true ;;
--start-omniparser) START_OMNIPARSER=true ;;
--help|-h)
cat <<EOF
MacWright setup and permission doctor
Usage:
./setup.sh Install deps, build, run permission checks
./setup.sh --doctor Run checks only; do not install/build
./setup.sh --open-settings Open relevant macOS Privacy settings panes
./setup.sh --install-omniparser Also run omniparser/setup.sh
./setup.sh --start-omniparser Start OmniParser after setup/checks
Important:
macOS permissions cannot be silently bypassed by scripts. You must manually
approve Accessibility, Screen Recording, and app-specific Automation prompts.
This script preflights, opens the right panes, and verifies readiness.
EOF
exit 0
;;
esac
done
open_privacy_pane() {
local pane="$1"
open "x-apple.systempreferences:com.apple.preference.security?$pane" >/dev/null 2>&1 || true
}
find_cmd() {
local cmd="$1"
if command -v "$cmd" >/dev/null 2>&1; then
command -v "$cmd"
return 0
fi
case "$cmd" in
brew)
for candidate in /opt/homebrew/bin/brew /usr/local/bin/brew; do
if [ -x "$candidate" ]; then
echo "$candidate"
return 0
fi
done
;;
cliclick)
for candidate in /opt/homebrew/bin/cliclick /usr/local/bin/cliclick; do
if [ -x "$candidate" ]; then
echo "$candidate"
return 0
fi
done
;;
esac
return 1
}
check_command() {
local cmd="$1"
local path
if path="$(find_cmd "$cmd")"; then
ok "$cmd found: $path"
return 0
fi
fail "$cmd not found"
return 1
}
check_accessibility() {
# This asks System Events for process names. If the controlling terminal/app is
# not approved under Accessibility, macOS returns an Apple Events/TCC error.
if osascript -e 'tell application "System Events" to get name of first process' >/dev/null 2>&1; then
ok "Accessibility permission works for this controlling app"
return 0
fi
fail "Accessibility permission is missing for this controlling app"
info "Required for: mouse, keyboard, scroll, drag, AX read/click, window control."
info "Grant the app that launches MacWright: Terminal/iTerm/Ghostty/Claude Desktop/Hermes runner."
return 1
}
check_screen_recording() {
# screencapture may still create a file when permission is denied, but on modern
# macOS it usually fails or captures unusable blank/desktop-only output. This is
# a practical smoke check, not a private TCC database inspection.
local tmp
tmp="$(mktemp -t macwright-screen.XXXXXX).jpg"
if /usr/sbin/screencapture -x -t jpg "$tmp" >/dev/null 2>&1 && [ -s "$tmp" ]; then
ok "Screen capture command works"
rm -f "$tmp"
return 0
fi
rm -f "$tmp"
fail "Screen Recording permission appears missing or screencapture failed"
info "Required for: screenshot, screen_parse, visual verification, wait_for_change."
info "Grant the app that launches MacWright under Screen Recording."
return 1
}
check_mouse_keyboard() {
local cliclick_bin
if ! cliclick_bin="$(find_cmd cliclick)"; then
fail "cliclick missing; mouse/keyboard primitives unavailable"
info "Install with: brew install cliclick"
return 1
fi
if "$cliclick_bin" p: >/dev/null 2>&1; then
ok "cliclick can read mouse position: $cliclick_bin"
return 0
fi
fail "cliclick failed; Accessibility permission is likely missing"
return 1
}
check_node_build() {
if [ ! -f "$SCRIPT_DIR/dist/index.js" ]; then
fail "dist/index.js missing; run ./setup.sh to build"
return 1
fi
ok "MacWright build artifact exists: $SCRIPT_DIR/dist/index.js"
}
check_omniparser() {
if curl -fsS --max-time 2 http://127.0.0.1:8650/health >/dev/null 2>&1; then
ok "OmniParser is running on http://127.0.0.1:8650"
return 0
fi
warn "OmniParser is not running"
info "Required only for: screen_parse visual UI detection."
info "Start with: npm run omniparser:start"
return 1
}
check_safari() {
local dev=false
if defaults read com.apple.Safari IncludeDevelopMenu 2>/dev/null | grep -q 1; then
dev=true
fi
if [ "$dev" = true ]; then
ok "Safari Develop menu is enabled"
else
warn "Safari Develop menu is not enabled"
info "Optional. Needed for safari_js tools. Enable Safari > Settings > Advanced > Show features for web developers."
fi
info "Safari JavaScript from Apple Events still must be enabled manually: Safari > Develop > Allow JavaScript from Apple Events."
}
run_validation() {
local failures=0
step "Permission and capability checks"
check_accessibility || failures=$((failures + 1))
check_screen_recording || failures=$((failures + 1))
check_mouse_keyboard || failures=$((failures + 1))
check_node_build || failures=$((failures + 1))
check_omniparser || true
check_safari || true
step "MacWright native MCP smoke test"
if npm run test:macos-smoke; then
ok "Native MCP smoke test passed"
else
failures=$((failures + 1))
fail "Native MCP smoke test failed"
fi
if [ "$OPEN_SETTINGS" = true ] || [ "$failures" -gt 0 ]; then
step "Opening macOS Privacy panes"
info "You must manually enable permissions; scripts cannot silently grant them."
info "After changing permissions, restart the controlling app before re-running ./setup.sh --doctor."
open_privacy_pane Privacy_Accessibility
open_privacy_pane Privacy_ScreenCapture
open_privacy_pane Privacy_ListenEvent
open_privacy_pane Privacy_Automation
fi
return "$failures"
}
cat <<'EOF'
MacWright Setup / Doctor
========================
macOS permissions cannot be bypassed silently. This script installs dependencies,
builds MacWright, opens the right Privacy panes when needed, and verifies whether
the current controlling app can actually automate the desktop.
EOF
cd "$SCRIPT_DIR"
if [ "$MODE" != "doctor" ]; then
step "Dependency setup"
cliclick_bin=""
if cliclick_bin="$(find_cmd cliclick)"; then
ok "cliclick is installed: $cliclick_bin"
else
warn "cliclick not found; installing via Homebrew"
brew_bin=""
if ! brew_bin="$(find_cmd brew)"; then
fail "Homebrew not found. Install it first: https://brew.sh"
exit 1
fi
"$brew_bin" install cliclick
if cliclick_bin="$(find_cmd cliclick)"; then
ok "cliclick installed: $cliclick_bin"
else
fail "cliclick install completed but binary was not found in PATH, /opt/homebrew/bin, or /usr/local/bin"
exit 1
fi
fi
if ! command -v node >/dev/null 2>&1; then
fail "node is missing. Install Node.js >= 18 before continuing."
exit 1
fi
ok "node $(node --version)"
step "Install and build"
npm install --silent
npm run build
ok "Build complete"
fi
if [ "$INSTALL_OMNIPARSER" = true ]; then
step "OmniParser setup"
if [ -x "$SCRIPT_DIR/omniparser/setup.sh" ]; then
(cd "$SCRIPT_DIR/omniparser" && ./setup.sh)
ok "OmniParser setup finished"
else
fail "omniparser/setup.sh not found or not executable"
fi
fi
if [ "$START_OMNIPARSER" = true ]; then
step "Starting OmniParser"
npm run omniparser:start || warn "OmniParser start command returned non-zero"
fi
if run_validation; then
step "Result"
ok "MacWright is ready for native desktop automation from this controlling app."
else
step "Result"
warn "MacWright setup is incomplete. Grant the missing permissions, restart the controlling app, then run: ./setup.sh --doctor"
fi
step "MCP configuration"
cat <<JSON
Claude Desktop / generic MCP clients:
{
"mcpServers": {
"macwright": {
"command": "node",
"args": ["${SCRIPT_DIR}/dist/index.js"]
}
}
}
Hermes Agent (~/.hermes/config.yaml):
mcp_servers:
macwright:
command: "node"
args: ["${SCRIPT_DIR}/dist/index.js"]
timeout: 120
connect_timeout: 30
JSON
echo ""