how to get windows of NSRunningApplication
Asked Answered
A

1

12

I want to get the window list for a running application. I can get the running application list from [[NSWorkspace sharedWorkspace] runningApplications], but the window list is only available on NSApplication. Is there some way to convert from NSRunningApplication to NSApplication, or some way to get the window list more directly?

Archdeaconry answered 7/12, 2012 at 9:57 Comment(4)
Here is the same question, already answered: #2108157Perfervid
Even here #13760188Magnificat
Widow list more directly means?Magnificat
thanks. i'll check those two, then come back if i need something.Archdeaconry
D
10

You need to look at the CoreGraphics call CGWindowListCopyWindowInfo.

You call it like this

    CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);

and then iterate over the array of window information, find the ones that are from the application you're interested in, and do what you want with it.

Deceleron answered 7/12, 2012 at 15:35 Comment(2)
Hey Ken! That's a good answer/hint, but it still doesn't tell how to get the CG/NSWindow ;-) NSRunningApplication doesn't provide windows/window number and I'm crashing (probably doing something wrong) when trying to get the NS/CGWindow with my CGWindowID obtained with CGWindowListCopyWindowInfoLifetime
That's because you can't create an NSWindow for another application. As far as getting the windows for a specific application, you can examine and compare the value of the kCGWindowOwnerPID key to the processIdentifier property of NSRunningApplication.Pessa

© 2022 - 2024 — McMap. All rights reserved.