Teo Choong Ping
Teo Choong Ping

Reputation: 12808

How to obtain info of the program from the window list with CGWindowListCopyWindowInfo

I managed to get list of windows on the desktop with CGWindowListCopyWindowInfo, but the next time is to try to get the properties of the window, like the program name, title, and other properties.

What API should I look into and do we have any example on how to do this?

Upvotes: 3

Views: 2212

Answers (1)

Anne
Anne

Reputation: 27073

List the windows and retrieve the specific information while looping through:

NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);

for (NSDictionary *window in windows) {
    NSString *owner = [window objectForKey:@"kCGWindowOwnerName" ];
    NSString *name = [window objectForKey:@"kCGWindowName" ];
    NSLog(@"%@ - %@",owner,name);
}

Available keys:

kCGWindowIsOnscreen
kCGWindowLayer 
kCGWindowMemoryUsage
kCGWindowName
kCGWindowNumber
kCGWindowOwnerName
kCGWindowOwnerPID
kCGWindowSharingState
kCGWindowStoreType

Upvotes: 9

Related Questions