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 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp