run_applescript
Execute AppleScript commands on macOS to automate tasks or control applications through the Coyote MCP Server.
Instructions
Executes an AppleScript command using osascript on macOS.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | AppleScript code to execute. |
Implementation Reference
- src/index.ts:34-61 (handler)The handler function for the 'run_applescript' tool. It spawns an 'osascript' process with the provided script, captures stdout and stderr, and returns the result or error message.async ({ script }) => { return new Promise((resolve) => { const proc = spawn("osascript", ["-e", script]); let output = ""; let error = ""; proc.stdout.on("data", (data) => { output += data.toString(); }); proc.stderr.on("data", (data) => { error += data.toString(); }); proc.on("close", (code) => { const result = code === 0 ? (output.trim() || "Command executed successfully") : `Error: ${error.trim() || "Unknown error"}`; resolve({ content: [{ type: "text", text: result }] }); }); }); }
- src/index.ts:30-32 (schema)Input schema for the 'run_applescript' tool, defining a required 'script' string parameter.inputSchema: { script: z.string().describe("AppleScript code to execute.") }
- src/index.ts:25-62 (registration)Registration of the 'run_applescript' tool using server.registerTool, including name, schema, and handler.server.registerTool( "run_applescript", { title: "Run AppleScript", description: "Executes an AppleScript command using osascript on macOS.", inputSchema: { script: z.string().describe("AppleScript code to execute.") } }, async ({ script }) => { return new Promise((resolve) => { const proc = spawn("osascript", ["-e", script]); let output = ""; let error = ""; proc.stdout.on("data", (data) => { output += data.toString(); }); proc.stderr.on("data", (data) => { error += data.toString(); }); proc.on("close", (code) => { const result = code === 0 ? (output.trim() || "Command executed successfully") : `Error: ${error.trim() || "Unknown error"}`; resolve({ content: [{ type: "text", text: result }] }); }); }); } );