Control macOS GUI applications (Finder, Mail, Safari) via JavaScript for Automation (JXA) with osascript
domain: developer.apple.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Save a JXA script with a .js extension or pass inline with osascript -l JavaScript -e 'var app = Application("Finder"); app.activate();'.
Obtain an application reference with Application("AppName") and set app.includeStandardAdditions = true to access standard addition verbs like display dialog.
Call scriptable properties as zero-argument functions: var win = Application("Safari").windows[0]; var url = win.currentTab.url();
Use the ObjC bridge (ObjC.import("Foundation")) for file I/O or Cocoa calls: var fm = $.NSFileManager.defaultManager; var exists = fm.fileExistsAtPath('/tmp/test');
Run the script file with osascript -l JavaScript myscript.js and pass arguments accessible via $.NSProcessInfo.processInfo.arguments.
Known gotchas
JXA uses camelCase method names that mirror ObjC selectors with colons replaced by capital letters; calling ObjC methods requires matching the exact translated name.
Not all applications expose a full scripting dictionary to JXA; check Script Editor's Library panel to confirm scriptability before writing automation.
Error messages from JXA are often terse; wrap sections in try/catch and log ObjC.unwrap() on NSError objects to get readable descriptions.
Give your agent this knowledge — and 15,500+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?