Run a one-line AppleScript from the terminal: `osascript -e 'tell application "Finder" to open folder "Desktop" of home'`.
For longer scripts, save them as `.applescript` or `.scpt` files and execute with `osascript myscript.applescript`, passing positional arguments accessible inside the script as `item 1 of argv`.
Use the Script Editor app (`/System/Applications/Script Editor.app`) to explore an application's dictionary (File > Open Dictionary) and discover the objects, properties, and commands it exposes.
Control System Events for UI automation of apps without a scripting dictionary: `tell application "System Events" to tell process "MyApp" to click button "OK" of window 1`.
Wrap osascript calls in shell scripts to compose multi-step automations, capturing output with `result=$(osascript -e '...')` for use in subsequent steps.
Known gotchas
macOS requires explicit user consent for Accessibility access before System Events-based UI automation works. The script host (Terminal, your app, CI runner) must be granted Accessibility permission in System Preferences > Privacy & Security > Accessibility — otherwise System Events commands silently fail or error.
Application names in `tell application` blocks must match exactly the name shown in Activity Monitor or the Finder. If the app name contains spaces or version numbers in its bundle, the script may fail to target the right process.
AppleScript UI element indices (`button 1`, `window 1`) are 1-based and ordered by creation time, not visual position. The order can change between app versions or after layout changes — prefer targeting elements by name or description attributes where available for more resilient scripts.
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