NSRunningApplication does not have specific app window

834 Views Asked by At

I want my application to know which all apps are currently running and show in a table. In table it will show all running apps names with a button beside each app. On Click of button we have to open the window of the specific app even if it is minimized or closed. I have got the running apps list by following code but not getting windows of the app as NsRunningApplication object does not have any window or view. Can anyone please help me?

NSMutableArray* mOpendAppsArray = [[NSMutableArray alloc] init];
NSMutableArray* mOpenedAppsNamesArray = [[NSMutableArray alloc] init]; 
NSUInteger count = [[[NSWorkspace sharedWorkspace] runningApplications] count]; 
for (NSUInteger i = 0; i < count; i++) {
    NSRunningApplication *app = [[[NSWorkspace sharedWorkspace] runningApplications] objectAtIndex: i];

    if(app.activationPolicy == NSApplicationActivationPolicyRegular) {
        [mOpenedAppsNamesArray addObject:app.localizedName];
        [mOpendAppsArray addObject:app];
    }
}
1

There are 1 best solutions below

0
On

If you get the bundleID of the app in addition to the localized name (which is what you are displaying in your table, I assume), you can activate the app using something like:

NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.bla.blah"];
[(NSRunningApplication*)[apps objectAtIndex:0] activateWithOptions: NSApplicationActivateAllWindows];