home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!news.nd.edu!resis
- From: claytor.1@nd.edu (Nelson Claytor)
- Subject: How do I use the 'miscdosc' AppleEvent?
- Message-ID: <claytor.1-171292131137@resis.phys.nd.edu>
- Followup-To: comp.sys.mac.programmer
- Sender: news@news.nd.edu (USENET News System)
- Organization: University of Notre Dame
- Date: Thu, 17 Dec 1992 18:18:40 GMT
- Lines: 163
-
- I'm having some trouble using the 'dosc' Apple Event to convince
- another application to run a script. So far, I'm basically testing only
- with
- Alpha, which returns an error number that is not defined in IM VI, nor
- in the AE Registry. Alpha returns -1769. Does anyone see anything obvious
- wrong with what I'm doing? My code follows the .sig.
-
- On a related note, does anyone have a reasonable routine for coercing
- text into typeIntlText in a general way? I can see simply sticking in the
- US English codes for language and script, but this certainly wouldn't
- be the "internationally correct" way to do things.
-
- Nelson Claytor | "As the people here grow colder,
- claytor.1@nd.edu | I turn to my computer,
- 1061 Riverside Drive | And spend my evenings with it
- South Bend, IN 46616 | Like a friend..." -- Kate Bush
-
- #include <Types.h>
- #include <Events.h>
- #include <Aliases.h>
- #include <PPCToolbox.h>
- #include <AppleEvents.h>
- #include <AERegistry.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- Boolean goodTarget;
- AEAddressDesc myTarget;
-
- /*****
- * DoScript()
- *
- * Bring up the PPCBrowser dialog to find an appropriate application,
- * then send the 'dosc' AppleEvent to make the app execute the specified
- script file.
- *
- *****/
- OSErr DoScript(void)
- {
- OSErr anErr,ret2;
- AppleEvent message, reply;
- TargetID theTarget;
- PortInfoRec thePortInfo;
- char *pathName;
- short pathNameLength;
- AliasHandle theAlias;
- AliasRecord alias;
- long aliasLength;
- short gotmess, gotrepl, gotscript;
- Size theSize;
- DescType theType;
- long errNumber;
- long funcLength;
- char *theFunction;
- AEDesc theScript;
- Str255 errStr;
-
- StandardFileReply theSFR;
- SFTypeList theTypeList;
-
- gotmess = gotrepl = gotscript = false;
- /* Find the target */
- anErr = PPCBrowser("\pSelect an Application","\pApplication", false,
- &theTarget.location,&thePortInfo,nil,"\p");
- if (!anErr) {
- theTarget.name = thePortInfo.name;
- myTarget.descriptorType = typeTargetID;
- anErr = PtrToHand((Ptr) &theTarget, &myTarget.dataHandle,
- sizeof(theTarget));
- }
-
- goodTarget = (anErr == noErr);
-
- if (goodTarget) {
- while (1)
- {
- /* Get the script file to be executed */
- StandardGetFile(nil,-1,theTypeList,&theSFR);
- if (theSFR.sfGood) {
- /* Make an alias to it */
- anErr = NewAliasMinimal(&(theSFR.sfFile),&theAlias);
- if (!anErr) { /* Handle Errors */
- }
- if (!theAlias) { /* Alias not created if theAlias == nil */
- }
- }
-
- /*
- * create the Apple Event message, then put the direct object into it
- */
-
- if ((anErr = AECreateAppleEvent(kAEMiscStandards, kAEDoScript,
- &myTarget, kAutoGenerateReturnID,
- kAnyTransactionID, &message)) != noErr)
- break;
- gotmess = true;
-
- /* Make a descriptor record of type typeAlias to contain the alias record
- */
- alias = **theAlias;
- aliasLength = (long)(alias.aliasSize);
- if ((anErr = AECreateDesc(typeAlias,(Ptr)&alias,aliasLength,&theScript))
- != noErr)
- break;
- gotscript = true;
-
- /* Put the descriptor record in as the direct object parameter */
- if ((anErr = AEPutParamDesc(&message,keyDirectObject,&theScript))
- != noErr)
- break;
-
- /*
- * send the Apple Event, but do not wait for the reply
- */
-
- if ((anErr = AESend(&message, &reply, kAEWaitReply+
- kAECanInteract+kAECanSwitchLayer,
- kAENormalPriority,
- 120, nil, nil)) != noErr)
- break;
- gotrepl = true;
-
- /* Deal with the reply */
- anErr = AEGetParamPtr(&reply,keyErrorNumber,typeLongInteger,&theType,
- (Ptr)&errNumber,sizeof(errNumber),&theSize);
- if (errNumber != noErr) {
- /* look for errorString */
- anErr = AEGetParamPtr(&reply,keyErrorString,typeIntlText,&theType,
- (Ptr)&errStr,sizeof(errStr),&theSize);
- }
-
- break;
-
- } /* end of while (1) */
-
- /*
- * dispose of any and all remaining AE records
- */
-
- if (gotmess)
- {
- ret2 = AEDisposeDesc(&message);
- if (anErr == noErr)
- anErr = ret2;
- }
-
- if (gotrepl)
- {
- ret2 = AEDisposeDesc(&reply);
- if (anErr == noErr)
- anErr = ret2;
- }
-
- if (gotscript)
- {
- ret2 = AEDisposeDesc(&theScript);
- if (anErr == noErr)
- anErr = ret2;
- }
- } /* end of if (goodTarget...) */
-
- return anErr;
- }
-