How to list all windows from all workspaces in Python on Mac?

Viewed 2412

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?

2 Answers
Related