close_window
Close a specific window on Windows by providing its title. This tool helps automate window management tasks for system control and workflow automation.
Instructions
关闭指定窗口
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | 窗口标题 |
Input Schema (JSON Schema)
{
"properties": {
"title": {
"description": "窗口标题",
"type": "string"
}
},
"required": [
"title"
],
"type": "object"
}
Implementation Reference
- src/tools/window.js:203-218 (handler)The core handler function that implements the close_window tool logic. Uses PowerShell script to find processes matching the window title and gracefully closes their main window.async closeWindow(title) { try { // 使用 taskkill 通过窗口标题关闭 const script = ` $processes = Get-Process | Where-Object { $_.MainWindowTitle -like "*${title}*" } foreach ($proc in $processes) { $proc.CloseMainWindow() | Out-Null } `; await execAsync(`powershell -Command "${script}"`, { shell: 'powershell.exe' }); return { success: true, window: title, message: '窗口已关闭' }; } catch (error) { return { success: false, error: error.message }; } }
- src/tools/window.js:41-51 (schema)Schema definition for the close_window tool within getToolDefinitions(), specifying input requirements.{ name: 'close_window', description: '关闭指定窗口', inputSchema: { type: 'object', properties: { title: { type: 'string', description: '窗口标题' }, }, required: ['title'], }, },
- src/tools/window.js:78-80 (registration)Registration of 'close_window' in the array of supported tools for the canHandle() method.const tools = ['list_windows', 'get_active_window', 'activate_window', 'close_window', 'minimize_window', 'maximize_window']; return tools.includes(toolName);
- src/tools/window.js:91-92 (handler)Routing case in the executeTool() switch statement that dispatches to the closeWindow handler.case 'close_window': return await this.closeWindow(args.title);