run-applescript

repository·main·Indexed 41 days ago

https://github.com/sindresorhus/run-applescript

A utility for executing AppleScript from JavaScript and TypeScript environments. Version 7.1.0 provides asynchronous execution via runAppleScript() and synchronous execution via runAppleScriptSync(), with options to control human-readable output and execution cancellation using AbortSignal.

Tokens
457
Snippets
4
Records
4
Agent score
1%

What's inside run-applescript

  1. Run AppleScript synchronously with runAppleScriptSync()

    main

    Use runAppleScriptSync to execute an AppleScript and receive the result as a string immediately. This will block the execution thread until the script completes.

    import {runAppleScriptSync} from 'run-applescript';
    
    const result = runAppleScriptSync('return "unicorn"');
    
    console.log(result);
    //=> 'unicorn'
  2. Run AppleScript asynchronously with runAppleScript()

    main

    Use runAppleScript to execute an AppleScript and receive the result as a Promise<string>. This is the preferred method for non-blocking execution.

    import {runAppleScript} from 'run-applescript';
    
    const result = await runAppleScript('return "unicorn"');
    
    console.log(result);
    //=> 'unicorn'
  3. Configure runAppleScript options

    main

    Both runAppleScript and runAppleScriptSync accept an optional options object to control execution behavior:

    • humanReadableOutput (boolean, default: true): Determines the output format. If set to false, the result is returned in a recompilable source form.
    • signal (AbortSignal): An AbortSignal that can be used to cancel the AppleScript execution (available in runAppleScript).
    // Example using humanReadableOutput: false
    const result = await runAppleScript('return "unicorn"', {
    	nonHumanReadable: false
    });