Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Wait for launched app to exit?

0 views
Skip to first unread message

Howard

unread,
Aug 24, 2004, 5:15:50 PM8/24/04
to
Hi,

I've recently added code to launch another application from my current
app (both are carbon apps I've written, and can modify as needed), using the
call LSOpenFSRef. This iw working fine, but now I'd like the ability to
wait for the launched app to exit before the launching itself continues (and
exits). I don't see any way to do this, even with LaunchApplication. Is
there any way to do this in for carbon applications (*not* Mach-O bundles)?
(Specifics would help immensely here...)

Thanks,
-Howard


Miro Jurisic

unread,
Aug 24, 2004, 5:43:15 PM8/24/04
to
In article <aeOWc.510568$Gx4.2...@bgtnsc04-news.ops.worldnet.att.net>,
"Howard" <ali...@hotmail.com> wrote:

When an app exits, you get a carbon event of class kEventClassApplication and
kind kEventAppTerminated. See if the PSN in that event is the PSN of what you
launched.

hth

meeroh

--
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>

Paul

unread,
Aug 24, 2004, 5:57:04 PM8/24/04
to

"Miro Jurisic" <mac...@meeroh.org> wrote in message
news:macdev-482F48....@senator-bedfellow.mit.edu...


I've done this using LaunchApplication and waiting for a ChildDied
AppleEvent (I had to support 8.6.) I didn't know about the carbon event
meeroh mentioned, but it looks like a much easier way to go.


Howard

unread,
Aug 24, 2004, 5:59:17 PM8/24/04
to

"Miro Jurisic" <mac...@meeroh.org> wrote in message
news:macdev-482F48....@senator-bedfellow.mit.edu...
> In article <aeOWc.510568$Gx4.2...@bgtnsc04-news.ops.worldnet.att.net>,
> "Howard" <ali...@hotmail.com> wrote:
>
> > I've recently added code to launch another application from my
current
> > app (both are carbon apps I've written, and can modify as needed), using
the
> > call LSOpenFSRef. This iw working fine, but now I'd like the ability to
> > wait for the launched app to exit before the launching itself continues
(and
> > exits). I don't see any way to do this, even with LaunchApplication.
Is
> > there any way to do this in for carbon applications (*not* Mach-O
bundles)?
> > (Specifics would help immensely here...)
>
> When an app exits, you get a carbon event of class kEventClassApplication
and
> kind kEventAppTerminated. See if the PSN in that event is the PSN of what
you
> launched.
>
> hth
>
> meeroh

Great! I'll try that first thing in the morning. Thanks...

-Howard


Howard

unread,
Aug 25, 2004, 1:06:32 PM8/25/04
to

"Miro Jurisic" <mac...@meeroh.org> wrote in message
news:macdev-482F48....@senator-bedfellow.mit.edu...
> In article <aeOWc.510568$Gx4.2...@bgtnsc04-news.ops.worldnet.att.net>,
> "Howard" <ali...@hotmail.com> wrote:
>
> > I've recently added code to launch another application from my
current
> > app (both are carbon apps I've written, and can modify as needed), using
the
> > call LSOpenFSRef. This iw working fine, but now I'd like the ability to
> > wait for the launched app to exit before the launching itself continues
(and
> > exits). I don't see any way to do this, even with LaunchApplication.
Is
> > there any way to do this in for carbon applications (*not* Mach-O
bundles)?
> > (Specifics would help immensely here...)
>
> When an app exits, you get a carbon event of class kEventClassApplication
and
> kind kEventAppTerminated. See if the PSN in that event is the PSN of what
you
> launched.
>
> hth
>
> meeroh

I'm not able to figure out how to recognize this event...? I've tried using
SetEventMask to get high-level events, and checked for high-level events
using EventAvail, but no luck.

I'm using modal dialogs in my first app, and can't easily redesign the whole
thing to handle event callbacks...I need to loop so I can return a value to
the calling dialog when I'm done waiting.

But whether using EventAvail or a callback, I also can't figure out how to
check for that class and kind. The EventRecord documentation doesn't
specify how I would determine "class" and "kind" in any manner that makes
sense. (I tried using the address of the "where" member as the address of
an OSType, and comparing the value there against kEventAppTerminated, but
that doesn't work, (and I'm not sure it makes any sense in the first place).
Likewise, where would I extract the PSN from?

Do you (or anyone) have any sample code where one app loops until another
app terminates? (This is so easy in Windows...I'm beginning to actually
*prefer* Windows! <shudder>)

Thanks,
Howard


Reinder Verlinde

unread,
Aug 25, 2004, 2:36:49 PM8/25/04
to
In article
<sG3Xc.246897$OB3.1...@bgtnsc05-news.ops.worldnet.att.net>,
"Howard" <ali...@hotmail.com> wrote:

> I'd like the ability to wait for the launched app to exit

"Miro Jurisic" <mac...@meeroh.org> answered:

! When an app exits, you get a carbon event of class
! kEventClassApplication and kind kEventAppTerminated. See if the PSN in
! that event is the PSN of what you launched.

Howard replied:

> I'm not able to figure out how to recognize this event...? I've tried using
> SetEventMask to get high-level events, and checked for high-level events
> using EventAvail, but no luck.

> [...]


> I also can't figure out how to check for that class and kind.
> The EventRecord documentation doesn't specify how I would determine
> "class" and "kind" in any manner that makes sense. (I tried using the
> address of the "where" member as the address of an OSType, and
> comparing the value there against kEventAppTerminated, but that
> doesn't work, (and I'm not sure it makes any sense in the first place).
> Likewise, where would I extract the PSN from?

It looks like you are lost in a dark corner of Mac OS programming. You
seem to be using the old (1984-ish) EventRecord structure,
WaitNextEvent, etc, as described in
<http://developer.apple.com/documentation/Carbon/Reference/Event_Manager/
index.html>

For new code, you should use Carbon Events, as described in
<http://developer.apple.com/documentation/Carbon/Conceptual/Carbon_Event_
Manager/index.html> It provides a much richer event model that does not
require your application to poll for events. Miro assumed that you were
using that event model.

Reinder

Howard

unread,
Aug 25, 2004, 3:40:20 PM8/25/04
to

"Reinder Verlinde" <rei...@verlinde.invalid> wrote in message
news:reinder-53DA4B...@reader10.wxs.nl...

Ok, after some (exhausting!) searching, I've found out how to manually check
for Carbon Events. (As I said, I can't drop out and wait on the events.)
And I've also researched how to get the PSN from the event. But, how do I
get the PSN from the launched app? Using LaunchApplication, it's the return
value. But I'm using LSOpenFSRef! I don't see any way to get the PSN from
the returned FSRef. Any ideas?

Thanks for all the help...

-Howard

Reinder Verlinde

unread,
Aug 25, 2004, 4:27:52 PM8/25/04
to
In article
<EW5Xc.247533$OB3.1...@bgtnsc05-news.ops.worldnet.att.net>,
"Howard" <ali...@hotmail.com> wrote:

> Ok, after some (exhausting!) searching, I've found out how to manually check
> for Carbon Events. (As I said, I can't drop out and wait on the events.)
> And I've also researched how to get the PSN from the event. But, how do I
> get the PSN from the launched app? Using LaunchApplication, it's the return
> value. But I'm using LSOpenFSRef! I don't see any way to get the PSN from
> the returned FSRef. Any ideas?

I think the following will do what you want:
Call GetProcessInformation on the PSN, find the process' FSSpec in the
processAppSpec field, call FSpMakeFSRef to convert it to a FSRef.

Reinder

Howard

unread,
Aug 25, 2004, 5:18:01 PM8/25/04
to

"Miro Jurisic" <mac...@meeroh.org> wrote in message
news:macdev-482F48....@senator-bedfellow.mit.edu...
> In article <aeOWc.510568$Gx4.2...@bgtnsc04-news.ops.worldnet.att.net>,
> "Howard" <ali...@hotmail.com> wrote:
>
> > I've recently added code to launch another application from my
current
> > app (both are carbon apps I've written, and can modify as needed), using
the
> > call LSOpenFSRef. This iw working fine, but now I'd like the ability to
> > wait for the launched app to exit before the launching itself continues
(and
> > exits). I don't see any way to do this, even with LaunchApplication.
Is
> > there any way to do this in for carbon applications (*not* Mach-O
bundles)?
> > (Specifics would help immensely here...)
>
> When an app exits, you get a carbon event of class kEventClassApplication
and
> kind kEventAppTerminated. See if the PSN in that event is the PSN of what
you
> launched.
>
> hth
>
> meeroh

Ok, I've rewritten the software to use LaunchApplication (so I can get the
PSN), and have added a loop to manually call ReceiveNextEvent to check for
that event. But ReceiveNextEvent never returns! Is there something I have
to do first to register my app to receive that event? Here's what my code
looks like (excuse any typos..my newsreader's on the PC while my code's on
the Mac!)...

EventTypeSpec eventType;
eventType.eventClass = kEventClassApplication;
eventType.eventKind = kEventAppTerminated;
while (ReceiveNextEvent( 1, &eventType, kEventDurationForever, false,
&theEvent ) == noErr)
{
/// here I compare the PSN's, and see if they match, and break out of the
loop if they do
}

I know the timeout is infinite, and that's why it will remain in
ReceiveNextEvent forever, but only if it never receives an event of that
type. (Right?) Which makes me think my app needs to somethow register
itself as receiving that type of event.

Any ideas what's wrong now?

Thanks,
Howard

Reinder Verlinde

unread,
Aug 25, 2004, 5:50:59 PM8/25/04
to
In article <dm7Xc.247947$OB3....@bgtnsc05-news.ops.worldnet.att.net>,
"Howard" <ali...@hotmail.com> wrote:

> Ok, I've rewritten the software to use LaunchApplication (so I can get the
> PSN), and have added a loop to manually call ReceiveNextEvent to check for
> that event. But ReceiveNextEvent never returns! Is there something I have
> to do first to register my app to receive that event? Here's what my code
> looks like (excuse any typos..my newsreader's on the PC while my code's on
> the Mac!)...

The Carbon Event Manager will only send you those events you
specifically ask it for. Look up InstallEventHandler (in your case
probably using the macro InstallApplicationEventHandler)
<http://developer.apple.com/documentation/Carbon/Conceptual/Carbon_Event_
Manager/Tasks/chapter_18_section_4.html#//apple_ref/doc/uid/TP30000989-CH
203-TPXREF105>

Reinder

Howard

unread,
Aug 25, 2004, 6:29:59 PM8/25/04
to

"Reinder Verlinde" <rei...@verlinde.invalid> wrote in message
news:reinder-601069...@reader11.wxs.nl...

Yes! It's working now! :-D I didn't think I could use an event handler,
since I'm looping instead of dropping out to the main event loop. But
adding an application event handler that receives only that event (and
simply returns noErr) seems to solve the problems.

Thanks a million!
-Howard


Howard

unread,
Aug 25, 2004, 6:49:46 PM8/25/04
to

Oh, one note, for other who might want to do this: In my earlier post I
passed false to ReceiveNextEvent for the flag that specified whether to pull
in the event (so that I own it). That needs to be true, and, as in the
Apple example, it then needs to be passed on to the appropriate target and
released. Otherwise, it never gets removed from the queue.

-Howard


0 new messages