Friday, September 20, 2013

Starting an application/process from code in OS X

NSString *strArg = @"arg";  //specifying the variable arg
    
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:@"Full-Path-To-The-App-To-Start"]];  //e.g. /Applications/TextEdit.app

NSError *error = nil;
NSArray *arguments = [NSArray arrayWithObjects:@"-d", @"-b", strArg, nil];
[workspace launchApplicationAtURL:url options:0 configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error :&error];

//Handle error


No comments:

Post a Comment