[comp.sys.mac.programmer] Need to be able to detect application start/finish

rjc@css.itd.umich.edu (Robert John Churchill) (05/21/91)

I am writing an INIT that needs to notice whenever an application opens
or closes (MultiFinder only). Currently, I've:
 
  *  patched InitGraf to notice when an application opens... this works
     great for my needs. Of course, INITs can call InitGraf as well, but
     I'm also checking to see if the OSDispatch trap is around (indicating
     that MultiFinder calls I need are around) & so I only notice Applications
     (and, of course, DAs under System 7 when they open).
 
  *  I've tried patching ExitToShell (at INIT time) but it seems that
     MultiFinder takes over this trap, and won't "pass it on". Should I
     give an attempt to patching ExitToShell at "InitGraf time"? 
 
  *  I've also tried patching out the "CloseResFile" trap to see when the
     give application's resource file is closed at exit time. This appears
     to work, and the refNum I'm picking off the stack appears correct,
     but I want to compare this to the low memory global CurApRefNum which
     appears NOT to be correct!
 
Even though I could check for Apple Events, I don't want to as this would
slow down the event process, and I need this to work for System 6 as well.
 
Any thoughts on this matter would be greatly appreciated. Either post here,
or e-mail me at:   rjc@um.cc.umich.edu

PS:  In article 25136 of comp.sys.mac.programmer, Michael Dautermann writes:
         ...
>  Would somebody take a few seconds and look at this code and let me
>  know what I am doing wrong?  Thanks so much for any help...
 
Mike, come see me Monday, Wednesday, or Friday at my cube at Argus (yes, I'm
Argus certified these days) and I can solve your problem for you. Let me know
your e-mail address so I can keep messages local to us.  :)
 
Robert

 
--
  Robert_John_Churchill@um.cc.umich.edu
  University of Michigan ITD Consulting & Support Services
  Mac/Dos/Unix Consultant III, Programmer, and undergraduate
  PC2 archivist - mac.archive.umich.edu (141.211.168.70)

gurgle@well.sf.ca.us (Pete Gontier) (05/22/91)

rjc@css.itd.umich.edu (Robert John Churchill) writes:

>I am writing an INIT that needs to notice whenever an application opens
>or closes (MultiFinder only). Currently, I've:
>  *  patched InitGraf to notice when an application opens...

This isn't going to work by itself. Whenever the "Please insert the disk
'blah blah'" alert is posted, the system calls InitGraf. You'll be
seeing an app start up twice.

>     Of course, INITs can call InitGraf as well, but
>     I'm also checking to see if the OSDispatch trap is around

Better to check the length byte of CurApName for -1. That way you work under
UniFinder. Either this, or patch Launch and patch InitGraf at the first Launch
and de-activate the Launch patch.

>  *  I've tried patching ExitToShell (at INIT time) but it seems that
>     MultiFinder takes over this trap, and won't "pass it on". Should I
>     give an attempt to patching ExitToShell at "InitGraf time"?

No reason not to, except with the above reservations about patching InitGraf.

>  *  I've also tried patching out the "CloseResFile" trap to see when the
>     give application's resource file is closed at exit time. This appears
>     to work, and the refNum I'm picking off the stack appears correct,
>     but I want to compare this to the low memory global CurApRefNum which
>     appears NOT to be correct!

This sounds sketchy. In most cases, the app is responsible for having called
ExitToShell. But it isn't responsible for closing its own resfile. I wouldn't
bother chasing this one much farther, because if Apple changes the sequence
of events, you could be screwed later, even if you figure it out for now.

>Even though I could check for Apple Events, I don't want to as this would
>slow down the event process, and I need this to work for System 6 as well.

I'm not sure what this is in reference to -- your OSDispatch strategy?
-- 
 Pete Gontier, gurgle@well.sf.ca.us
 Software Imagineer, Kiwi Software, Inc.