Run AppleScript
Runs AppleScript with osascript and captures its result.
Run AppleScript script
Keyboard Maestro: ExecuteAppleScript
Details #
Sends script to /usr/bin/osascript on standard input. The text the script returns (what osascript prints) is captured with trailing newlines removed. If into is set, that variable gets this text.
The step's output is an object with stdout, exit (always 0, since any other exit fails the step) and, if there was any, stderr. A script error fails the step with exit <code>: followed by the first 300 characters of the error message, which is AppleScript's own error text.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
script | text | Yes | Required. The AppleScript source. | |
args | text | Text handed to the script as its arguments, one per line (or a list). AppleScript gets them as the list in on run argv. | ||
into | text | The variable that receives the result text. | ||
sample | any value | What into holds during a dry run. | ||
timeout | number | Seconds before the step is cancelled. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
- Run AppleScript “tell application "Finder" to get name…”
- Show “Finder: {{win}}”
Gotchas #
Dry run. The script does not run.
intois set tosample, or to an empty string without one.Timeout. Cancelled after 10 s by default. A script that waits on a dialog or a slow app needs
timeout.Permissions. The first time a script controls another app, macOS asks whether Switchboard may control it. If you said no, the step fails with an error about not being authorized. Fix it in System Settings › Privacy & Security › Automation.
Do not put secrets in the script text: it is saved with the macro and shown in the trace.