Run AppleScript One-Liners from the Terminal
Drive apps, windows, and dialogs with a single osascript -e command.
Run osascript -e '…AppleScript…' to execute one script statement and get its result in the shell.
01Command
Command
$ osascript -e 'tell application "Safari" to activate'02What it does
osascript bridges the shell to AppleScript: -e takes one statement, several -e flags stack into a multi-line script, and a script file runs with osascript script.applescript. When embedding shell variables, build the string carefully — use double quotes outside and single inside. The last expression prints to stdout, so a get command returns values you can pipe onward.
03Risk
!Warning: Scripts that control other apps need Automation permission — grant it once when macOS prompts, or the command silently fails.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- osascript – Execute AppleScript and OSA scriptsEvidence: osascript -e executes a single AppleScript statement from the command line; multiple -e flags chain statements.
Last verified: 2026-09-18 · Category: Developer