可能有不同的方法,其中一种是枚举正在运行的应用程序,另一种是枚举应用程序中的窗口。
我将在这里展示应用程序方法
from AppKit import NSApplication, NSApp, NSWorkspace
from Quartz import kCGWindowListOptionOnScreenOnly, kCGNullWindowID, CGWindowListCopyWindowInfo
workspace = NSWorkspace.sharedWorkspace()
activeApps = workspace.runningApplications()
for app in activeApps:
if app.isActive():
options = kCGWindowListOptionOnScreenOnly
windowList = CGWindowListCopyWindowInfo(options,
kCGNullWindowID)
for window in windowList:
if window['kCGWindowOwnerName'] == app.localizedName():
print(window.getKeys_)
break
break
app
找到了。你可以使用
app.hide()
你可以使用
from Cocoa import NSApplicationActivateIgnoringOtherApps, NSApplicationActivateAllWindows
app.unhide()
app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)
# or
app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps | NSApplicationActivateAllWindows)
OS X: Move window from Python
How to list all windows from all workspaces in Python on Mac?
How to get Window reference (CGWindow, NSWindow or WindowRef) from CGWindowID in Swift?
"No such file: 'requirements.txt' error" while installing Quartz module
How to build Apple's Son of grab example?
How to get another application window's title, position and size in Mac OS without Accessibility API?
Get the title of the current active Window/Document in Mac OS X
-[NSRunningApplication activateWithOptions:] not working
How to start an app in the foreground on Mac OS X with Python?
set NSWindow focused
Activate a window using its Window ID