run_jxa
Execute JavaScript for Automation (JXA) code to control macOS system tasks and automate workflows directly from AI assistants.
Instructions
Execute JavaScript for Automation (JXA) code on macOS
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | JXA JavaScript code to execute |
Implementation Reference
- src/index.js:228-245 (handler)The core handler function that executes the JXA script using osascript with JavaScript language flag.
async runJXA(script) { try { const result = execSync(`osascript -l JavaScript -e '${script.replace(/'/g, "'\"'\"'")}'`, { encoding: 'utf8', }); return { content: [ { type: 'text', text: result.trim() || 'Script executed successfully', }, ], }; } catch (error) { throw new Error(`JXA error: ${error.message}`); } } - src/index.js:51-64 (registration)Registration of the 'run_jxa' tool in the ListTools response, including description and input schema.
{ name: 'run_jxa', description: 'Execute JavaScript for Automation (JXA) code on macOS', inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JXA JavaScript code to execute', }, }, required: ['script'], }, }, - src/index.js:54-63 (schema)Input schema definition for the 'run_jxa' tool, specifying the 'script' parameter.
inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JXA JavaScript code to execute', }, }, required: ['script'], }, - src/index.js:178-179 (handler)Dispatch handler in CallToolRequest that routes 'run_jxa' calls to the runJXA method.
case 'run_jxa': return await this.runJXA(args.script);