trigger_moom_action
Execute Moom window layout actions like grow, shrink, move, or center using customizable keyboard shortcuts for efficient macOS workspace management.
Instructions
Trigger common Moom actions via keyboard shortcuts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Moom action to trigger |
Implementation Reference
- src/index.js:342-394 (handler)The main handler function that maps the input 'action' to specific Moom keyboard shortcuts and simulates them using AppleScript via System Events.async triggerMoomAction(action) { // Map actions to Moom keyboard shortcuts const shortcuts = { 'grow': { key: '=', modifiers: 'control down, option down' }, 'shrink': { key: '-', modifiers: 'control down, option down' }, 'move-left': { key: '123', modifiers: 'control down, option down' }, // left arrow 'move-right': { key: '124', modifiers: 'control down, option down' }, // right arrow 'move-up': { key: '126', modifiers: 'control down, option down' }, // up arrow 'move-down': { key: '125', modifiers: 'control down, option down' }, // down arrow 'center': { key: 'c', modifiers: 'control down, option down' }, 'fill-screen': { key: 'return', modifiers: 'control down, option down' }, }; const shortcut = shortcuts[action]; if (!shortcut) { return { content: [ { type: 'text', text: `Unknown action: ${action}`, }, ], }; } const script = ` tell application "System Events" ${shortcut.key.length > 1 ? `key code ${shortcut.key} using {${shortcut.modifiers}}` : `keystroke "${shortcut.key}" using {${shortcut.modifiers}}`} end tell `; try { await this.runAppleScript(script); return { content: [ { type: 'text', text: `Successfully triggered Moom action: ${action}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error: ${error.message}`, }, ], }; } }
- src/index.js:59-73 (schema)Input schema definition for the trigger_moom_action tool, specifying the required 'action' parameter with allowed enum values.{ name: 'trigger_moom_action', description: 'Trigger common Moom actions via keyboard shortcuts', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['grow', 'shrink', 'move-left', 'move-right', 'move-up', 'move-down', 'center', 'fill-screen'], description: 'Moom action to trigger', }, }, required: ['action'], }, },
- src/index.js:213-214 (registration)Tool dispatch/registration in the CallToolRequestSchema handler switch statement, routing to the triggerMoomAction method.case 'trigger_moom_action': return await this.triggerMoomAction(args.action);
- src/index.js:238-247 (helper)Helper utility function used by the handler to execute AppleScript commands asynchronously.async runAppleScript(script) { try { const { stdout, stderr } = await execAsync(`osascript -e '${script}'`); if (stderr) { throw new Error(stderr); } return stdout.trim(); } catch (error) { throw new Error(`AppleScript error: ${error.message}`); }