home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19978 < prev    next >
Encoding:
Text File  |  1992-12-17  |  4.6 KB  |  175 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!news.nd.edu!resis
  3. From: claytor.1@nd.edu (Nelson Claytor)
  4. Subject: How do I use the 'miscdosc' AppleEvent?
  5. Message-ID: <claytor.1-171292131137@resis.phys.nd.edu>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: news@news.nd.edu (USENET News System)
  8. Organization: University of Notre Dame
  9. Date: Thu, 17 Dec 1992 18:18:40 GMT
  10. Lines: 163
  11.  
  12. I'm having some trouble using the 'dosc' Apple Event to convince 
  13. another application to run a script. So far, I'm basically testing only
  14. with
  15. Alpha, which returns an error number that is not defined in IM VI, nor
  16. in the AE Registry. Alpha returns -1769. Does anyone see anything obvious
  17. wrong with what I'm doing? My code follows the .sig.
  18.  
  19. On a related note, does anyone have a reasonable routine for coercing
  20. text into typeIntlText in a general way? I can see simply sticking in the
  21. US English codes for language and script, but this certainly wouldn't
  22. be the "internationally correct" way to do things.
  23.  
  24. Nelson Claytor                        | "As the people here grow colder,
  25. claytor.1@nd.edu                      |   I turn to my computer,
  26. 1061 Riverside Drive                  |   And spend my evenings with it
  27. South Bend, IN 46616                  |   Like a friend..." -- Kate Bush
  28.  
  29. #include <Types.h>
  30. #include <Events.h>
  31. #include <Aliases.h>
  32. #include <PPCToolbox.h>
  33. #include <AppleEvents.h>
  34. #include <AERegistry.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37.  
  38. Boolean                    goodTarget;
  39. AEAddressDesc            myTarget;
  40.  
  41. /*****
  42.  * DoScript()
  43.  *
  44.  *    Bring up the PPCBrowser dialog to find an appropriate application,
  45.  *    then send the 'dosc' AppleEvent to make the app execute the specified
  46. script file.
  47.  *
  48.  *****/
  49. OSErr DoScript(void)
  50. {
  51.     OSErr                anErr,ret2;
  52.     AppleEvent            message, reply;
  53.     TargetID            theTarget;
  54.     PortInfoRec            thePortInfo;
  55.     char                *pathName;
  56.     short                pathNameLength;
  57.     AliasHandle            theAlias;
  58.     AliasRecord            alias;
  59.     long                aliasLength;
  60.     short                gotmess, gotrepl, gotscript;
  61.     Size                theSize;
  62.     DescType            theType;
  63.     long                errNumber;
  64.     long                funcLength;
  65.     char                *theFunction;
  66.     AEDesc                theScript;
  67.     Str255                errStr;
  68.     
  69.     StandardFileReply    theSFR;
  70.     SFTypeList            theTypeList;
  71.  
  72.     gotmess = gotrepl = gotscript = false;
  73. /* Find the target */
  74.     anErr = PPCBrowser("\pSelect an Application","\pApplication", false,
  75.                         &theTarget.location,&thePortInfo,nil,"\p");
  76.     if (!anErr) {
  77.         theTarget.name = thePortInfo.name;
  78.         myTarget.descriptorType = typeTargetID;
  79.         anErr = PtrToHand((Ptr) &theTarget, &myTarget.dataHandle,
  80. sizeof(theTarget));
  81.     }
  82.  
  83.     goodTarget = (anErr == noErr);
  84.  
  85.     if (goodTarget) {
  86.         while (1)
  87.         {
  88.         /* Get the script file to be executed */
  89.         StandardGetFile(nil,-1,theTypeList,&theSFR);
  90.         if (theSFR.sfGood) {
  91.             /* Make an alias to it */
  92.             anErr = NewAliasMinimal(&(theSFR.sfFile),&theAlias);
  93.             if (!anErr) { /* Handle Errors */
  94.             }
  95.             if (!theAlias) { /* Alias not created if theAlias == nil */
  96.             }
  97.         }
  98.         
  99.         /*
  100.          * create the Apple Event message, then put the direct object into it
  101.          */
  102.  
  103.         if ((anErr = AECreateAppleEvent(kAEMiscStandards, kAEDoScript,
  104.                                         &myTarget, kAutoGenerateReturnID,
  105.                                         kAnyTransactionID, &message)) != noErr)
  106.             break;
  107.         gotmess = true;
  108.  
  109.     /* Make a descriptor record of type typeAlias to contain the alias record
  110. */
  111.         alias = **theAlias;
  112.         aliasLength = (long)(alias.aliasSize);
  113.         if ((anErr = AECreateDesc(typeAlias,(Ptr)&alias,aliasLength,&theScript))
  114.                     != noErr) 
  115.                 break;
  116.         gotscript = true;
  117.         
  118.     /* Put the descriptor record in as the direct object parameter */
  119.         if ((anErr = AEPutParamDesc(&message,keyDirectObject,&theScript))
  120.                     != noErr) 
  121.                 break;
  122.                         
  123.         /*
  124.          * send the Apple Event, but do not wait for the reply
  125.          */
  126.  
  127.         if ((anErr = AESend(&message, &reply, kAEWaitReply+
  128.                                     kAECanInteract+kAECanSwitchLayer,
  129.                                     kAENormalPriority,
  130.                                     120, nil, nil)) != noErr)
  131.             break;
  132.         gotrepl = true;
  133.  
  134. /* Deal with the reply */
  135.         anErr = AEGetParamPtr(&reply,keyErrorNumber,typeLongInteger,&theType,
  136.                              (Ptr)&errNumber,sizeof(errNumber),&theSize);
  137.         if (errNumber != noErr) {
  138.         /* look for errorString */
  139.         anErr = AEGetParamPtr(&reply,keyErrorString,typeIntlText,&theType,
  140.                              (Ptr)&errStr,sizeof(errStr),&theSize);
  141.         }
  142.         
  143.         break;
  144.  
  145.         }    /* end of while (1) */
  146.  
  147.     /*
  148.      * dispose of any and all remaining AE records
  149.      */
  150.  
  151.     if (gotmess)
  152.         {
  153.         ret2 = AEDisposeDesc(&message);
  154.         if (anErr == noErr)
  155.             anErr = ret2;
  156.         }
  157.  
  158.     if (gotrepl)
  159.         {
  160.         ret2 = AEDisposeDesc(&reply);
  161.         if (anErr == noErr)
  162.             anErr = ret2;
  163.         }
  164.  
  165.     if (gotscript)
  166.         {
  167.         ret2 = AEDisposeDesc(&theScript);
  168.         if (anErr == noErr)
  169.             anErr = ret2;
  170.         }
  171.     }        /* end of if (goodTarget...) */
  172.  
  173.     return anErr;
  174. }
  175.