The following Python 2 code prints list of all windows in the current workspace:
#!/usr/bin/python
import Quartz
for window in Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID):
print("%s - %s" % (window['kCGWindowOwnerName'], window.get('kCGWindowName', u'Unknown').encode('ascii','ignore')))
Although it doesn't print the applications which are in full screen (as it's in another workspace).
How do I modify above script to list all windows from all desktops?
The key is here to use the right option for the 1st argument of
CGWindowListCopyWindowInfo
. So apart of usingoptionOnScreenOnly
property (which list all windows that are currently onscreen),excludeDesktopElements
property needs to be added.E.g.
Alternatively for all windows,
kCGWindowListOptionAll
property can be also used.For other properties, check
CGWindow.h
inCoreGraphics
.So the original code can be changed to:
The following script should return window information on any desktop/workspace/display, fullscreen, and detailed information (coordinates, pid, titles, etc.):