index.d.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. export type Options = {
  2. /**
  3. Change the output style.
  4. When `false`, returns the value in a [recompilable source form](https://ss64.com/osx/osascript.html).
  5. @default true
  6. @example
  7. ```
  8. import {runAppleScript} from 'run-applescript';
  9. const result = await runAppleScript('return "unicorn"', {humanReadableOutput: false});
  10. console.log(result);
  11. //=> '"unicorn"'
  12. ```
  13. */
  14. readonly humanReadableOutput?: boolean;
  15. /**
  16. An AbortSignal that can be used to cancel the AppleScript execution.
  17. Only supported by the async function.
  18. */
  19. readonly signal?: AbortSignal;
  20. };
  21. /**
  22. Run AppleScript asynchronously.
  23. @param script - The script to run.
  24. @returns The script result.
  25. @example
  26. ```
  27. import {runAppleScript} from 'run-applescript';
  28. const result = await runAppleScript('return "unicorn"');
  29. console.log(result);
  30. //=> 'unicorn'
  31. ```
  32. */
  33. export function runAppleScript(
  34. script: string,
  35. options?: Options
  36. ): Promise<string>;
  37. /**
  38. Run AppleScript synchronously.
  39. @param script - The script to run.
  40. @returns The script result.
  41. @example
  42. ```
  43. import {runAppleScriptSync} from 'run-applescript';
  44. const result = runAppleScriptSync('return "unicorn"');
  45. console.log(result);
  46. //=> 'unicorn'
  47. ```
  48. */
  49. export function runAppleScriptSync(script: string, options?: Options): string;