Is there a way to get list of open or visible NSWindow from mac desktop?
Asked
Active
Viewed 1.0k times
13
-
Here is how to get running window informations in macOS https://github.com/onmyway133/blog/issues/243 – onmyway133 May 16 '19 at 13:46
3 Answers
26
Note that not all windows are necessarily NSWindows
, and that NSWindow
only provides an interface to windows in your own address space.
The supported way to access every window is the CGWindow
API. Take a look at the Son of Grab sample code to see how it's done.

Anoop Vaidya
- 46,283
- 15
- 111
- 140

Chuck
- 234,037
- 30
- 302
- 389
-
-
-
Why not all windows are necessarily NSWindows? Then what are those cgwindows super class? Could you give me a reference to look it up? – allenlinli Aug 04 '16 at 13:00
5
You can use the accessibility API (accessibility must be enabled under System Preferences for it to work) to get information on windows (and other UI elements) from other processes. This question might be just what you're looking for.
2
ALL running applications? No. You can only get the NSWindows of your own app. You may be able to use Universal Access or Core Graphics APIs to get some information about windows of other apps, but not full access.

JWWalker
- 22,385
- 6
- 55
- 76
-
3To get the `NSWindow`s of your own app, you can use `[[NSApplication sharedApplication] windows]` (in case anyone is looking for such a thing, and stumbled on this question) – aleclarson Jan 24 '19 at 16:18