Send macOS user notifications and display modal dialogs from shell scripts using 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. Use osascript -e 'display notification "message" with title "Title" subtitle "Sub"' to post a Notification Center alert from the command line.
  2. For a blocking modal, use osascript -e 'display dialog "message" with title "Title" buttons {"Cancel", "OK"} default button "OK"' and capture the button returned.
  3. Check the exit code (0 = OK/default, 1 = cancel/closed) when driving logic from the dialog result.
  4. For scripted workflows needing user input, add 'default answer "placeholder"' to display dialog to show a text-entry field; retrieve via 'text returned of result'.
  5. Wrap osascript calls in a shell function and test on the target macOS version — display notification behaviour via Terminal may differ on newer OS releases.

Known gotchas

Related routes

Automate macOS applications using AppleScript via osascript from the command line or scripts
developer.apple.com · 5 steps · unrated
Control macOS GUI applications (Finder, Mail, Safari) via JavaScript for Automation (JXA) with osascript
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