Hi Ken,

Thanks for the prompt reply. I got a better insight into the APIs. But
somehow I am not able to fix my problem.

I am using following:

NSTask* task = [NSTask launchedTaskWithLaunchPath:@"path" arguments:args];
int pid  = [task processIdentifier];
ProcessSerialNumber psn;
GetProcessForPID(pid, &psn);
SetFrontProcess(&psn);
[task waitUntilExit];
SetFrontProcess(&psn);

Even on switching to NSWorkSpace doesn't seem to solve the purpose. The
launched application does not get highlighted. Also, one more issue I am
facing is how to send custom events from launched application to parent
application. Thanks in advance.

On Sat, Apr 17, 2010 at 7:13 PM, Ken Thomases <k...@codeweavers.com> wrote:

> On Apr 17, 2010, at 8:14 AM, Gaurav Srivastava wrote:
>
> > I was working with NSTask and came across some issues. I searched on the
> > internet and found that there has been a similar query but that didn't
> have
> > any solution. The link for that is
> > http://lists.apple.com/archives/cocoa-dev//2003/May/msg01468.html. Could
> you
> > suggest any possible solution for this.
> >
> > Also, if my parent application has a non-modal dialog up, on launching
> > another app, it goes behind the non-modal dialog. Please suggest some
> > solution as I am stuck with it for last few days.
>
> To launch a secondary application, you should use NSWorkspace or Launch
> Services.  That will bring it to the front, even if it's already running.
>  To wait until it's finished, you can use the techniques outlined in this
> tech note <http://developer.apple.com/mac/library/technotes/tn/tn2050.html
> >.
>
> If you need to pass information into the other application, and you control
> the implementation of that application, I recommend using one of:
>
> * -[NSWorkspace launchApplicationAtURL:options:configuration:error:] with
> the relevant information in the configuration parameter
>
> * -[NSWorkspace
> launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:]
> with an AppleEvent descriptor
>
> * LSOpenFromURLSpec() with an AppleEvent descriptor in the passThruParams
> fields of the inLaunchSpec parameter
>
> You can also pass information into the application through a scripting
> interface.
>
>
> If you don't control the implementation of the other application and the
> above techniques don't suffice, you can use NSTask to launch it, but it
> wouldn't be my first choice.  If you need to bring it to the foreground,
> you'd want to use NSWorkspace to monitor for when it's launched and ready,
> and then activate it.  You know when it is launched when you receive the
> NSWorkspaceDidLaunchApplicationNotification notification which matches the
> application that you ran.  On 10.6 and later, you get an
> NSRunningApplication object with that notification, and you can activate it
> by invoking -activateWithOptions: on it.  For 10.5 and earlier, you get a
> dictionary that includes a ProcessSerialNumber, and you can use
> SetFrontProcess with that.
>
> Regards,
> Ken
>
>


-- 
Gaurav Srivastava
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to