1

I need to call another app from my app, and send it some command line arguments. Using launchApplication works well, but I don;t know how to send the command line arguments with it. System() will send command line args, but the app appears behind the calling app.

Thanks,

Bill

Bill
  • 305
  • 6
  • 25

1 Answers1

3

Have a look at this S.O. post for some hints.

Under Snow Leopard, you can use launchApplicationAtURL:options:configuration:error

to pass arguments. Simply build a configuration dictionary giving NSWorkspaceLaunchConfigurationArguments as key to your array of arguments.

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
  • It looks like you meant to include a link to another question, but didn't. – JWWalker Nov 23 '11 at 22:20
  • That worked great, thanks! Unfortunately the app appears beneath the one that called it. Is there a way to programmatically bring it to the front? – Bill Nov 24 '11 at 12:40
  • Have a look at this: http://stackoverflow.com/questions/2333078/how-to-launch-application-and-bring-it-to-front-using-cocoa-api – sergio Nov 24 '11 at 12:48
  • It still stays behind using that solution, although I had to change PID to pID to get it to compile: NSRunningApplication* myApp=[NSRunningApplication runningApplicationWithProcessIdentifier: pID]; [myApp activateWithOptions: NSApplicationActivateAllWindows]; – Bill Nov 24 '11 at 14:31
  • forgive me, but having to change PID to pID does not make any sense to me... just for clarity: PID (or whatever its name) should be the process id of the process you just started with `launchApplicationAtURL`; or just use the other syntax (bundle identifier)... if you don't have the PID (which I suspect), use the other syntax and specify the bundle identifier... – sergio Nov 24 '11 at 15:00
  • Sorry. I'm new at Cocoa. I tried the other method, [(NSRunningApplication*)[apps objectAtIndex:0] activateWithOptions: NSApplicationActivateAllWindows]; and I think I'm getting a good apps pointer (it's not null...), but it crashes when that line is run. – Bill Nov 24 '11 at 16:19
  • what error do you get (cmd-shift-r to display the console log) and what is the stack trace? – sergio Nov 24 '11 at 16:25
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5316/discussion-between-bill-ferster-and-sergio) – Bill Nov 24 '11 at 17:21