Launching an Mac App with Objective-C/Cocoa -
when launching path finder app command line, use open -a path finder.app /users/
. based on idea, use following code launch path finder.
can have launch app without using open
command line?
nstask *task; task = [[nstask alloc] init]; [task setlaunchpath: @"/usr/bin/open"]; nsarray *arguments; arguments = [nsarray arraywithobjects: @"-a", @"path finder.app", @"/users/", nil]; [task setarguments: arguments]; nspipe *pipe; pipe = [nspipe pipe]; [task setstandardoutput: pipe]; nsfilehandle *file; file = [pipe filehandleforreading]; [task launch];
if(![[nsworkspace sharedworkspace] launchapplication:@"path finder"]) nslog(@"path finder failed launch");
with parameters:
nsworkspace *workspace = [nsworkspace sharedworkspace]; nsurl *url = [nsurl fileurlwithpath:[workspace fullpathforapplication:@"path finder"]]; //handle url==nil nserror *error = nil; nsarray *arguments = [nsarray arraywithobjects:@"argument1", @"argument2", nil]; [workspace launchapplicationaturl:url options:0 configuration:[nsdictionary dictionarywithobject:arguments forkey:nsworkspacelaunchconfigurationarguments] error:&error]; //handle error
you use nstask pass arguments:
nstask *task = [[nstask alloc] init]; nsbundle *bundle = [nsbundle bundlewithpath:[[nsworkspace sharedworkspace] fullpathforapplication:@"path finder"]]]; [task setlaunchpath:[bundle executablepath]]; nsarray *arguments = [nsarray arraywithobjects:@"argument1", @"argument2", nil]; [task setarguments:arguments]; [task launch];
Comments
Post a Comment