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?
how to get windows of NSRunningApplication
Asked Answered
Here is the same question, already answered: #2108157 –
Perfervid
Even here #13760188 –
Magnificat
Widow list more directly means? –
Magnificat
thanks. i'll check those two, then come back if i need something. –
Archdeaconry
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.
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 CGWindowListCopyWindowInfo
–
Lifetime 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.