applescript.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * AppleScript Execution Utilities
  3. *
  4. * This module provides a safe interface for executing AppleScript commands
  5. * on macOS. It handles script execution, error capture, and result parsing.
  6. *
  7. * @module utils/applescript
  8. */
  9. import type { AppleScriptResult, AppleScriptOptions } from "../types.js";
  10. /**
  11. * Executes an AppleScript command and returns a structured result.
  12. *
  13. * This function serves as the bridge between TypeScript and macOS AppleScript.
  14. * It handles the complexity of shell escaping, execution, and error handling
  15. * so that calling code can work with clean TypeScript interfaces.
  16. *
  17. * The script is executed synchronously via the `osascript` command-line tool.
  18. * Multi-line scripts are supported and preserved (important for AppleScript
  19. * tell blocks and repeat loops).
  20. *
  21. * @param script - The AppleScript code to execute
  22. * @param options - Optional execution settings (timeout, etc.)
  23. * @returns A result object with success status and output or error message
  24. *
  25. * @example
  26. * ```typescript
  27. * // Basic usage with default timeout (30 seconds)
  28. * const result = executeAppleScript(`
  29. * tell application "Notes"
  30. * get name of every note
  31. * end tell
  32. * `);
  33. *
  34. * // With custom timeout for complex operations
  35. * const result = executeAppleScript(complexScript, { timeoutMs: 60000 });
  36. *
  37. * if (result.success) {
  38. * console.log("Notes:", result.output);
  39. * } else {
  40. * console.error("Failed:", result.error);
  41. * }
  42. * ```
  43. */
  44. export declare function executeAppleScript(script: string, options?: AppleScriptOptions): AppleScriptResult;
  45. //# sourceMappingURL=applescript.d.ts.map