Run AppleScript and OSA JavaScript from Hammerspoon scripts.
Script execution is isolated in a separate XPC helper process
(HammerspoonOSAScriptHelper). If a script crashes or deadlocks, only the
helper is affected — the main app remains stable and the next call
reconnects automatically.
Async API (Promise-based)
Every async function returns a Promise that always resolves (never rejects)
Field
Type
Description
success
Boolean
true if the script ran without error
result
any
Parsed return value of the script, or null on failure
raw
String
Raw string representation of the result, or the error message on failure
Sync API
The *Sync variants block until the script completes and return the same
{ success, result, raw } object directly. Use these only when a Promise
chain is impractical; they block the JS thread for the duration of the call.
The result field is typed based on what the script returned: strings,
numbers, booleans, lists, and records are all mapped to their JavaScript
equivalents. null is used for AppleScript's missing value and for any
failure case.
Run AppleScript and OSA JavaScript from Hammerspoon scripts. Script execution is isolated in a separate XPC helper process (
HammerspoonOSAScriptHelper). If a script crashes or deadlocks, only the helper is affected — the main app remains stable and the next call reconnects automatically.Async API (Promise-based)
Every async function returns a
Promisethat always resolves (never rejects)successBooleantrueif the script ran without errorresultanynullon failurerawStringSync API
The
*Syncvariants block until the script completes and return the same{ success, result, raw }object directly. Use these only when a Promise chain is impractical; they block the JS thread for the duration of the call. Theresultfield is typed based on what the script returned: strings, numbers, booleans, lists, and records are all mapped to their JavaScript equivalents.nullis used for AppleScript'smissing valueand for any failure case.Examples
Return a string (async):*
Return a string (sync):*
Interact with an application:*
Handle errors (the Promise never rejects — check
success):*OSA JavaScript:*
Run a script from a file:*