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

  1. Save a JXA script with a .js extension or pass inline with osascript -l JavaScript -e 'var app = Application("Finder"); app.activate();'.
  2. Obtain an application reference with Application("AppName") and set app.includeStandardAdditions = true to access standard addition verbs like display dialog.
  3. Call scriptable properties as zero-argument functions: var win = Application("Safari").windows[0]; var url = win.currentTab.url();
  4. Use the ObjC bridge (ObjC.import("Foundation")) for file I/O or Cocoa calls: var fm = $.NSFileManager.defaultManager; var exists = fm.fileExistsAtPath('/tmp/test');
  5. Run the script file with osascript -l JavaScript myscript.js and pass arguments accessible via $.NSProcessInfo.processInfo.arguments.

Known gotchas

Related routes

Script a native macOS app with JavaScript for Automation (JXA) instead of AppleScript
developer.apple.com · 5 steps · unrated
Automate macOS applications using AppleScript via osascript from the command line or scripts
developer.apple.com · 5 steps · unrated
Automate macOS native applications using AppleScript and System Events
developer.apple.com · 6 steps · unrated

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?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans