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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With