Archive

Posts Tagged ‘Cocoa’

BDD in the field

December 3rd, 2009 Sean DeNigris 2 comments

I am on fire about Ruby.  I always hated Objective-C’s weirdness (coming from C++), and read the most awesome idea recently – given the amazing power of modern computers (now pay attention, this is the good part): writing code in anything but the highest level, easiest language is… premature optimization!!!  The instant I read that statement (sorry to the author, I can’t remember where), I knew it was true.  Add that you can drop down from Ruby to lower level languages where you need extra speed, and that MacRuby and HotCoca are going to make it ridiculously easy to use Cocoa via Ruby and…

That’s it – I’m hooked.  To get myself up to speed in Ruby and Cocoa, I’m re-writing the examples from Aaron Hillegass’s awesome book Cocoa Programming for Mac OS X.  I’ll be writing about the intricacies of BDD in Ruby using Xcode, and I’ll be posting all the code, as well as custom file and project templates for Xcode.

Getting the process ID of a Mac App

July 15th, 2009 Sean DeNigris No comments

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, Software Engineering Tags: ,