Skip to content

Instantly share code, notes, and snippets.

@abhibeckert
Created June 14, 2013 01:33
Show Gist options
  • Save abhibeckert/5778794 to your computer and use it in GitHub Desktop.
Save abhibeckert/5778794 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import <Carbon/Carbon.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
// get list of running apps
NSMutableArray *runningApps = [NSMutableArray array];
ProcessSerialNumber psn = { kNoProcess, kNoProcess };
while (GetNextProcess(&psn) == noErr) {
CFDictionaryRef cfDict = ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
if (cfDict) {
NSDictionary *dict = (NSDictionary *)CFBridgingRelease(cfDict);
[runningApps addObject:[dict objectForKey:(id)kCFBundleNameKey]];
}
}
// decide which app to open
NSString *appPath = @"/Applications/Dux.app";
if ([runningApps containsObject:@"Xcode"]) {
appPath = @"/Applications/Xcode.app";
}
// open it
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:@[appPath]];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment