From: keith@taligent.com (Keith Rollin) Subject: Re: Need sample code of MPW tool using Apple Events Date: Fri, 18 Sep 1992 01:50:18 GMT In article <1992Sep17.181819.23018@oakhill.sps.mot.com>, tomc@oakhill.sps.mot.com (Tom Cunningham) wrote: > > > Does anyone have some code for an MPW tool using Apple Events that > they could send me? In particular, I want to communicate with the > Tool Server (e.g. run a script) via Apple Events from within an MPW > tool. Thanks. I used the following in a tool I wrote to kill and restart the Finder. This was in the hopes that shutting down the Finder would help speed up my long compiles (it didn't). Remember that you have to have one of the MPW Shells that comes with its High-Level Event Aware bit set: void KillFinder() { OSErr err; OSType signature = 'MACS'; AEAddressDesc target; AppleEvent theEvent; Str255 s; ProcessSerialNumber pPsn; err = FindProcessBySignature(signature, &pPsn); if (err == noErr) { err = AECreateDesc(typeProcessSerialNumber, (Ptr) &pPsn, sizeof(pPsn), &target); if (err == noErr) { err = AECreateAppleEvent('aevt', 'quit', &target, kAutoGenerateReturnID, kAnyTransactionID, &theEvent); if (err == noErr) { err = AESend(&theEvent, nil, kAENoReply, kAENormalPriority, kNoTimeOut, nil, nil); if (err != noErr) { fprintf(stderr, "### - Error while trying to send Apple Event.\n"); GetSysErrText(err, s); fprintf(stderr, "### %s.\n", s); exit(kBadAESend); } } else { fprintf(stderr, "### - Error while trying to create Apple Event.\n"); GetSysErrText(err, s); fprintf(stderr, "### %s.\n", s); exit(kBadAppleEvent); } } else { fprintf(stderr, "### - Error while trying to create Finder address.\n"); GetSysErrText(err, s); fprintf(stderr, "### %s.\n", s); exit(kBadAddress); } } else { fprintf(stderr, "### - Error while trying to get the FinderŐs psn.\n"); GetSysErrText(err, s); fprintf(stderr, "### %s.\n", s); exit(kCantFindFinder); } } I should point out that my call to FindProcessBySignature (a local routine that I didn't include here) is not necessary, and that creating the address using typeSignature should be sufficient. My calling FindProcessBySignature is there for historical reasons only. ----- Keith Rollin Phantom Programmer Taligent, Inc.