MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / execute

Method execute

src/tools/computer/use.ts:297–321  ·  view source on GitHub ↗
(_args: z.infer<typeof ActiveWindowArgs>, _ctx: ToolContext)

Source from the content-addressed store, hash-verified

295 argsSchema = ActiveWindowArgs;
296
297 async execute(_args: z.infer<typeof ActiveWindowArgs>, _ctx: ToolContext): Promise<ToolResult> {
298 if (!isMacos()) return macosOnly(this.name);
299 try {
300 const script = `tell application "System Events"
301 set frontApp to first application process whose frontmost is true
302 set appName to name of frontApp
303 try
304 set winTitle to title of window 1 of frontApp
305 set winPos to position of window 1 of frontApp
306 set winSize to size of window 1 of frontApp
307 return appName & "|" & winTitle & "|" & (item 1 of winPos) & "," & (item 2 of winPos) & "|" & (item 1 of winSize) & "x" & (item 2 of winSize)
308 on error
309 return appName & "|(no window)|0,0|0x0"
310 end try
311end tell`;
312 const { stdout } = await runCmd('osascript', ['-e', script], { timeoutMs: 5000 });
313 const [appName, winTitle, pos, size] = stdout.trim().split('|');
314 return {
315 content: `Active app: ${appName}\nWindow: ${winTitle}\nPosition: ${pos}\nSize: ${size}`,
316 metadata: { appName, windowTitle: winTitle, position: pos, size },
317 };
318 } catch (e: any) {
319 return { content: `[COMPUTER_USE_ERROR] ${e?.message ?? e}`, isError: true };
320 }
321 }
322}
323
324// ─────────────────────────────────────────────────────────────────────────────

Callers

nothing calls this directly

Calls 3

isMacosFunction · 0.85
macosOnlyFunction · 0.85
runCmdFunction · 0.85

Tested by

no test coverage detected