Launch app with params as front process and wait?
Launch app with params as front process and wait?
- Subject: Launch app with params as front process and wait?
- From: Steve Bennett <email@hidden>
- Date: Tue, 27 May 2003 13:30:44 -0400
Hi!
I have a situation where a Cocoa application I've written needs to launch an
arbitrary application. The applications are typically 3rd party, and cannot
be changed.
Most of these applications have UI that the user must respond to, so they
must be launched into the foreground. While it's running, my own
application has to sit quietly and wait for the launched application to
finish it's task. As soon as the launched application exits, my application
must bring it's own UI back to the foreground and resume processing.
Also, in at least one situation, the application can accept command line
parameters, which was there to allow the application to be run from a script
(it still presents some UI, though), and I'd like to be able to take
advantage of this if possible.
There appear to be two ways to launch an application in Cocoa, neither of
which does exactly what I need it to do:
1) Use NSTask to launch the application. This allows me to specify the
command line parameters and wait until the app finishes, but the
application's UI always appears in the background. I have not been able to
figure out a way around this so far, and none of my searches give me the
info I need.
I *do* see in NSTask an integer processIdentifier value, and if I had a
means of converting that to a processSerialNumber, I could then use the
Process Manager SetFrontProcess call to fix things, but I haven't found any
documentation on what the processIdentifier actually is or how I might be
able to convert it to a PSN, if at all possible.
2) Use NSWorkspace launchApplication to launch the application. This brings
up the application in the foreground, but doesn't wait for it to finish.
Now, by registering for the NSWorkspaceDidLaunchNotification, I can get the
Process Serial Number for the launched application, and then poll (on a
timer) the Process Manager to see if it's exited yet. I hate to have to use
a polling mechanism for this, but it's my fallback if nobody else has a
better alternative. Anybody?
The other problem with the NSWorkspace method, however, is that there is no
way to pass command line parameters to the app. It would simplify things
immensely if I can use them -- without it things get significantly more
complicated. Anyone have a way for doing this using this method?
-->Steve Bennett
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.