Skip to content

Instantly share code, notes, and snippets.

@panupan
Created November 10, 2011 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panupan/1354258 to your computer and use it in GitHub Desktop.
Save panupan/1354258 to your computer and use it in GitHub Desktop.
Cocoa / Obj-C - return the number of running application instances
- (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