Run JXA script
Runs JavaScript for Automation with osascript to control Mac apps.
Run JXA script
Keyboard Maestro: ExecuteJavaScriptForAutomation
Details #
Runs script as JavaScript for Automation (osascript -l JavaScript). This is the same engine as Run AppleScript, with JavaScript syntax, so it can script apps with Application("Finder"). Whatever the script returns as its last value is printed and becomes the output text. If into is set, that variable gets it.
The output is an object with stdout, exit and, if any, stderr. A script error fails the step with the first 300 characters of the message.
This step is not Run JavaScript. That one runs inside Switchboard with no access to apps, files or the network; JXA runs outside and can do anything your user can.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
script | text | Yes | Required. The JXA source. | |
args | text | Text handed to the script as its arguments, one per line (or a list). JavaScript gets them as the argument of function 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 JXA script “Application('System Events').processes.…”
- Show “Front app: {{front}}”
Gotchas #
Dry run. The script does not run;
intogetssample(or an empty string).Timeout. Cancelled after 10 s by default; set
timeoutfor longer jobs.Permissions. Controlling another app triggers a macOS Automation prompt, same as AppleScript. Fix refusals in System Settings › Privacy & Security › Automation.
Do not store secrets in the script text.