Automate macOS applications using AppleScript via osascript from the command line or scripts

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. Run a one-line AppleScript from the terminal: `osascript -e 'tell application "Finder" to open folder "Desktop" of home'`.
  2. 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`.
  3. 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.
  4. 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`.
  5. Wrap osascript calls in shell scripts to compose multi-step automations, capturing output with `result=$(osascript -e '...')` for use in subsequent steps.

Known gotchas

Related routes

Automate macOS native applications using AppleScript and System Events
developer.apple.com · 6 steps · unrated
Run and chain a macOS Shortcut from the command line alongside osascript
support.apple.com · 6 steps · unrated
Run macOS Shortcuts automations from the command line or from scripts
support.apple.com · 5 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