Browse the docs

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 #

ParameterTypeRequiredValuesWhat it does
scripttextYesRequired. The AppleScript source.
argstextText handed to the script as its arguments, one per line (or a list). AppleScript gets them as the list in on run argv.
intotextThe variable that receives the result text.
sampleany valueWhat into holds during a dry run.
timeoutnumberSeconds before the step is cancelled.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Read the name of the front Finder window (runs a script)
Do
  1. Run AppleScript “tell application "Finder" to get name…”
  2. Show “Finder: {{win}}”
Open in Switchboard to try it

Gotchas #

  • Dry run. The script does not run. into is set to sample, 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.

See also #

Run JXA script, Run shell script, Run Shortcut