Home > Mac, Programming > Getting the process ID of a Mac App

Getting the process ID of a Mac App

It seems like a common-enough problem, yet after striking out on the mailing list archives, coding sites, and Apple Developer Connection, I wrote this little Cocoa snippet to find the process ID of a particular app:

// Just replace this first string with your app name
NSString* target_app_name = @"Finder";
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSArray* active_apps = [workspace launchedApplications];
NSNumber* process_id = nil;

for (int i = 0; i < [active_apps count]; ++i) {
  NSDictionary* current_app = [active_apps objectAtIndex:i];
  NSString* app_name = [current_app valueForKey:@"NSApplicationName"];

  if ([app_name isEqualToString:target_app_name])
  process_id = [current_app valueForKey:@"NSApplicationProcessIdentifier"];
}
Categories: Mac, Programming Tags: ,

windows 7 product key

windows 7 product key

windows 7 key generator

windows 7 key generator

free winrar download

free winrar download

winzip activation code

winzip activation code

free winrar

free winrar

winzip free download

winzip free download

winrar free download

winrar free download

winrar download free

winrar download free

winzip free download full version

winzip free download full version

windows 7 activation crack

windows7 activation crack

windows 7 crack

windows 7 crack

free winzip

free winzip
\n