run_applescript
Execute AppleScript commands within macOS applications to automate tasks and control app functionality programmatically.
Instructions
Выполняет AppleScript команду в указанном приложении. Полезно для автоматизации действий в приложениях
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appName | Yes | Имя приложения (например, 'Safari', 'Finder') | |
| script | Yes | AppleScript команда для выполнения |
Implementation Reference
- src/server.py:339-345 (handler)Python handler function that executes the provided AppleScript in the context of the specified macOS application using osascript.def run_applescript(app_name: str, script: str) -> str: """Executes AppleScript command""" apple_script = f'tell application "{app_name}"\n{script}\nend tell' # Escape single quotes apple_script_escaped = apple_script.replace("'", "'\\''") stdout, stderr = exec_command(f"osascript -e '{apple_script_escaped}'") return stdout or stderr or "Command executed successfully"
- src/index.ts:447-472 (handler)TypeScript handler method that executes the provided AppleScript in the context of the specified macOS application using osascript.private async runAppleScript(appName: string, script: string) { try { // Выполняем AppleScript в контексте указанного приложения const appleScript = ` tell application "${appName}" ${script} end tell `; const { stdout, stderr } = await execAsync( `osascript -e '${appleScript.replace(/'/g, "'\\''")}'` ); return { content: [ { type: "text", text: stdout || stderr || "Команда выполнена успешно", }, ], }; } catch (error) { throw new Error( `Ошибка выполнения AppleScript: ${error instanceof Error ? error.message : String(error)}` ); }
- src/server.py:68-84 (schema)Input schema for the run_applescript tool in the Python MCP server."name": "run_applescript", "description": "Executes AppleScript command in specified application. Useful for automating actions in applications", "inputSchema": { "type": "object", "properties": { "appName": { "type": "string", "description": "Application name (e.g., 'Safari', 'Finder')", }, "script": { "type": "string", "description": "AppleScript command to execute", }, }, "required": ["appName", "script"], }, },
- src/index.ts:80-96 (schema)Input schema for the run_applescript tool in the TypeScript MCP server.name: "run_applescript", description: "Выполняет AppleScript команду в указанном приложении. Полезно для автоматизации действий в приложениях", inputSchema: { type: "object", properties: { appName: { type: "string", description: "Имя приложения (например, 'Safari', 'Finder')", }, script: { type: "string", description: "AppleScript команда для выполнения", }, }, required: ["appName", "script"], },