Created
June 14, 2013 01:33
-
-
Save abhibeckert/5778794 to your computer and use it in GitHub Desktop.
This file contains 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
#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