MCPcopy Index your code
hub / github.com/geekcomputers/Python / close_visible_window

Function close_visible_window

JARVIS/actions.py:30–50  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

28
29
30def close_visible_window(name):
31 if win32gui is None or win32con is None:
32 return "Close is not available because pywin32 is missing."
33 wanted = normalize_text(name)
34 if not wanted or wanted in BLOCKED_APPS:
35 return "That close request is blocked for safety."
36 matches = []
37
38 def callback(hwnd, _):
39 if not win32gui.IsWindowVisible(hwnd):
40 return
41 title = win32gui.GetWindowText(hwnd)
42 if wanted in normalize_text(title):
43 matches.append((hwnd, title))
44
45 win32gui.EnumWindows(callback, None)
46 if not matches:
47 return f"I could not find an open window matching {name}."
48 hwnd, title = matches[0]
49 win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
50 return f"Closing {title or name}."
51
52
53def is_safe_url(url):

Callers 1

run_actionFunction · 0.85

Calls 1

normalize_textFunction · 0.85

Tested by

no test coverage detected