Created
November 10, 2011 06:24
-
-
Save panupan/1354258 to your computer and use it in GitHub Desktop.
Cocoa / Obj-C - return the number of running application instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (int)instanceCount { | |
int i = 0; | |
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; | |
for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) { | |
if ([appName isEqualToString:[app localizedName]]) i++; | |
} | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment