Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get windows of NSRunningApplication

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?

like image 316
pvinis Avatar asked Dec 07 '12 09:12

pvinis


1 Answers

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.

like image 68
Ken Aspeslagh Avatar answered Oct 08 '22 12:10

Ken Aspeslagh