run_applescript
Execute AppleScript code on macOS to automate tasks, control applications, and perform system operations through the automator-mcp server.
Instructions
Execute AppleScript code on macOS
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | AppleScript code to execute |
Implementation Reference
- src/index.js:209-226 (handler)Executes the provided AppleScript code using the `osascript` command via Node.js `execSync`, with single quote escaping for safety. Returns the result as MCP content or throws an error.async runAppleScript(script) { try { const result = execSync(`osascript -e '${script.replace(/'/g, "'\"'\"'")}'`, { encoding: 'utf8', }); return { content: [ { type: 'text', text: result.trim() || 'Script executed successfully', }, ], }; } catch (error) { throw new Error(`AppleScript error: ${error.message}`); } }
- src/index.js:37-50 (registration)Registers the 'run_applescript' tool in the ListTools response, including name, description, and input schema.{ name: 'run_applescript', description: 'Execute AppleScript code on macOS', inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'AppleScript code to execute', }, }, required: ['script'], }, },
- src/index.js:40-49 (schema)Defines the input schema for the 'run_applescript' tool, requiring a 'script' property of type string.inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'AppleScript code to execute', }, }, required: ['script'], },
- src/index.js:175-176 (handler)Dispatches calls to the 'run_applescript' tool by invoking the runAppleScript method in the CallToolRequest handler.case 'run_applescript': return await this.runAppleScript(args.script);