run_applescript
Execute AppleScript commands in macOS applications to automate tasks and control app behavior programmatically.
Instructions
Выполняет AppleScript команду в указанном приложении. Полезно для автоматизации действий в приложениях
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appName | Yes | Имя приложения (например, 'Safari', 'Finder') | |
| script | Yes | AppleScript команда для выполнения |
Implementation Reference
- src/index.ts:447-473 (handler)TypeScript handler that constructs and executes AppleScript targeting the specified application using osascript command.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:339-346 (handler)Python handler that constructs and executes AppleScript targeting the specified application using osascript command.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:80-96 (schema)TypeScript input schema definition for the run_applescript tool.name: "run_applescript", description: "Выполняет AppleScript команду в указанном приложении. Полезно для автоматизации действий в приложениях", inputSchema: { type: "object", properties: { appName: { type: "string", description: "Имя приложения (например, 'Safari', 'Finder')", }, script: { type: "string", description: "AppleScript команда для выполнения", }, }, required: ["appName", "script"], },
- src/server.py:68-83 (schema)Python input schema definition for the run_applescript tool."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:314-318 (registration)TypeScript switch case dispatching to the runAppleScript handler.case "run_applescript": return await this.runAppleScript( args?.appName as string, args?.script as string );