Tclosascript - Exec for Mactcl

Tclosascript - Exec for Mactcl

The following paper was originally published in the Proceedings of the Fifth Annual Tcl/Tk Workshop Boston, Massachusetts, July 1997 TclOSAScript - Exec for MacTcl Jim Ingham Lucent Technologies (now at Sun Microsystems) Raymond Johnson Sun Microsystems For more information about USENIX Association contact: 1. Phone: 510 528-8649 2. FAX: 510 548-5738 3. Email: [email protected] 4. WWW URL: http://www.usenix.org TclOSAScript-ExecforMacTcl JimIngham LucentTechnologies (nowatSunMicrosystems) [email protected] RaymondJohnson SunMicrosystems [email protected] Abstract: WedescribetheTclOSAScriptextensiontoMacTcl.TclOSAScriptprovides theabilityforMacTclscriptstorunscriptsinanyotherOSAcompatible languageontheMacintosh.SincetheOSAisthestandardmechanismfor interapplicationcommunicationontheMac,thisallowsMacTcltorunother applications,andprovidesanexeclikefacility(thougharguablyusingamuch richercommunicationmodel.) I) AnIntroductiontotheOpen Tk95and96conferences[3,4].Therearetwo ScriptingArchitecture implementationsofthissolutionthathavebeen presented.TedBeldungwroteaextensioncalled Theusualinterapplicationcommunicationmecha- ASTcl[5]whichonlyworkedwithAppleScript,and nismforUnixbasedtoolsreliesonthesimpleex- didnotusemanyoftheadvancedfeaturestheOSA pedientofconnectingthestandardinandstan- offers.TclOSAScript,whichwasdevelopedcon- dardoutchannelsofthespawnedprocesstochan- currently,isamorecompleteimplementation.This nelsoftheparentprocess.Thecommunication istheonewewilldetailinthispaper. betweentheparentandchildprocessesthenmim- ThereisarealproblemthattheOSAaimstosolve icstheuserinteractionwiththeprocess,namely aswell–beyondthefactthattheremaywellnot typingcommandsonthecommandline.The beatextbasedcommandinterfacetotasksina “exec”commandinTcl,aswellastheopen-with- modernGUIoperatingsystem.Forwhilethecom- pipecommand,usethismechanismtogiveTclac- mand-basedformofcommunicationiseasyto cesstoprocessesinthesurroundingsystem. implement,toactuallydriveanapplicationyou Thismethod,unfortunately,isinapplicableon needtoknowtheparticularlanguagethattheap- Macintoshsystems.Macintoshapplicationsare plicationuses,beitsimplecommandlineswitches, onlyimplementedwithaGraphicalUserInterface orareallanguagesuchasTcl.Thereisnogeneric (GUI).Thereisnocommandline,andthusno waytoexposethefunctionalelementsofanappli- conceptofstandardinandstandardout.How- cationwithouttyingthemtoaparticularscripting ever,thisdoesnotmeanthereisnointerapplication language. communicationmechanism.Instead,amuchricher Thesolutionistodefinethebasicobjectsandverbs methodofscriptingexternaltasksisprovidedby thattheapplicationsupportsinalanguageneutral theOpenScriptingArchitecture(OSA)[1,2]. way.Thenthescriptinglanguagemustprovidea Thisproblem,andtheOSAsolutionpresentedhere, mechanismforqueryingouttheseelements.Fi- werefirstmentionedinpapersintheUsenixTcl/ nally,theoperatingsystemwillprovideamessag- ingsystemthatwillallowanyscriptinglanguage OneapplicationundertheMacOSsendsanApple todrivetheobjectsofthetargetapplication. Eventtoanotherapplicationbybuildingupthe AppleEventdatastructure,andthenpassingitto theAppleEventManager,whichplacestheevent a)SpecificationofVerbs&Objects–theaete intheeventqueueofthetargetapplication.The Thespecificationofobjectsisachievedwiththe targetapplicationthenhandlesthiseventbypars- AppleEventTerminologyExtension.Thisisaresource ingupitscontentsandperformingtherequired intheresourceforkoftheapplicationwhichlists task. the‘events’towhichtheapplicationresponds,and theclassesofobjectsintheapplication. c)OSAcompliantlanguages Examplesofeventsthatanapplicationmightrec- Allinterapplicationcommunicationiscarriedout, get set create ognizearethe‘ ’,‘ ’and‘ ’events, underthehood,bytheexchangeofAppleEvents. whichjustprovideaccesstotheobjectsintheap- However,thisistoolowlevelanexchangemecha- plication.Theseformpartofthe“StandardSuite” nismtobeusefultotheaverageuser. ofcommandsthatallwelldesignedOSAapplica- tionsshouldsupport.Therearealsomorespecial- ThejobofanOSAcompliantlanguage,then,isto izedverbs,suchas‘select’or‘revert’inaWord wrapamorehumansyntaxaroundtheconstruc- Processorappor‘ download’and‘ view file tionoftheAppleEventmessages.Theapproved list’intheFTPclientapplicationFetch.Events methodfordoingthisistoreadtheaeteofatarget alsotakeparameters,suchaswhichwordtoselect application,andimporttheverbsandnounsfound inawordprocessor,orwhichfiletodownloadin thereinintoitsownsyntaxinanaturalway.Done Fetch. thisway,theaetecanserveasdocumentationfor howtoscripteachlanguage,andthelanguagecan Examplesofobjectsarethewindowsofanapplica- dynamicallyappropriatenewapplicationsasthey tion,orthewordsandparagraphsinawordpro- areencountered. cessorwindow.Thereisalsoawayofspecifyinga containmenthierarchy,soeachobjectcanbecon- OfthetwomajorOSAcompliantlanguages,only tainedinotherobjects,andcancontainotherob- AppleScript[6]dynamicallyreadstheaeteofthe jects,.Finally,theobjectsmaytakequalifiers.An targetapplication.UserLandFrontier[7]hasastatic exampleofamoderatelycomplicatedobjectspeci- gluetableforeachapplicationthatrelatestheevent fier,inAppleScriptdialect,is:“ the file andobjectcodeswithcommandsintheFrontier “mactcltk-full-8.0a2” in the transfer language.Thislimitsthenumberofscriptableap- window “ftp.sunlabs.com” of the appli- plicationsthatFrontiercanactuallydrive. cation “Fetch 3.0.2””. Theaetemakestheconnectionbetweenthetext d)OSAComponents phrasewhichspecifiesanobjectorverb,andsome ThefinalpartoftheOSAarchitectureistheOSA packed4charactercodewhichwilloccurinthe component.Thisisanimplementationoftheno- compiledformoftheinterapplicationmessages.It tionthatascriptinglanguageisnotsomuchapart alsospecifiestheparametersfortheverbs(with oftheapplication,asaservicethatisprovidedto thenotionofrequiredandoptionalparameters), applications,toaidtheminexposingtheiropera- andthecontainmenthierarchyoftheobjects.Once tiveparts. youknowtheaeteofanapplication,youknowthe formanymessagetothatapplicationmusttake. Tclhasbeenverysuccessfulpreciselybecauseit makesiteasytobindtogetherthefunctionalele- b)TheMessagingsystem–AppleEvents mentsoftheapplicationwithouthavingto recompiletheapplication.ButtomakeuseofTcl, ThemessagingsystemintheOSAisgovernedby theapplicationmustembedaTclinterpreterwithin theAppleEventManager.AnAppleEventisa theobjectcodeoftheapplication.Thistiesthe datastructurethatdescribesaneventintermsof useoftheapplicationtoTcl;youcannotdynami- theaforementionedpacked4charactercodes.It callychoosewhichscriptinglanguageyouwantto startswiththemainverb,andthenusuallyhasa employ. directobjectwithitsqualifiers,andperhapsother parameters.AppleEventssupportnesting,sothat TheOSAgoesfurthertomaketheoperatingsys- asingleeventcansupportrecursiveevaluation temthemanagerofscriptingsolutions.Thepro- (muchlikethe[]syntaxinTcl). viderofascriptinglanguagewritessomegluecode thatregistersthescriptinglanguagewiththeoper- atingsystem.Applicationsrequestaconnectionto atedbythatcomponent.Currentlyconnections thescriptingcomponent,andthensendscriptdata tobothofthepopularOSAlanguages,AppleScript tothatcomponenttobeevaluated.Thescriptdata andUserLandFrontierhavebeentested. canevencontaintagsidentifyingitslanguage,so TclOSAScriptwillbeincludedasashareablelibrary thattheapplicationcanreceivescriptingdatain inthe8.0releaseofMacTcl.Whatfollowsisa anyoftheavailablelanguages,passittotheOSA generaldescriptionoftheTclOSAScriptextension. componentmanager,whichwillinturnrouteitto theappropriatecomponent. 1)TheOSAcommand Thisconnectioncanbeusedintwoways.Oneis ThefirststepinusinganyOSAcomponentisto toallowanapplicationtodriveotherapplications, getaconnectiontoaninstanceofthecomponent. sothatitdoesnothavetoduplicatetheirfunc- Atstartup,TclOSAScriptscansthelistofOSAcom- tionality.AgoodexampleofthisistheMicroSoft ponents,opensaconnectiontoeachonethatis InternetExplorer,whichhandsoffe-mail,FTPand found,andcreatesaTclcommandtoaccessthat NNTPrequeststotheuser’sfavoritee-mail,FTP component.SoiftheuserhasAppleScriptinstalled andUsenetclientsusingtheOSA. ontheirmachine,anAppleScriptcommandwill AdeeperuseoftheOSAisto“factor”theuser becreated.IfUserLandFrontierisrunningat interfaceelementsoftheapplicationfromitscore startup,a UserLand commandwillbecreated, functionality.Theuserinterfaceelementsdonot andsoon. directlycallthesubroutinesthatdotheworkof Thereisalsoagenericcommand, OSA,thatwill theapplication.RathertheysendAppleEventsback allowotherconnectionstobeopened,orclosed, totheapplication,whichreceivestheseevents,and andwillallowtheusertoquerythelistofcompo- thendispatchesthemtotheappropriateinternal nents.Thisisuseful,forinstance,toopenconnec- routines. tionswithotherlanguages. Theadvantageofthisisthatyoucanthen“attach” Anexampleofthisuseiscommunicationwiththe scriptstotheUIelements,whichscriptsdothe UserLandlanguage.TheUserLandOSAcompo- workofdispatchingtheAppleEvents.Thisimme- nentisinstalledonlywhiletheFrontierapplica- diatelyprovidesanarchitecturemuchlike tionisrunning.SoifyouwantedtouseFrontier, HyperCard,ortheTcl/Tkcallbacks,butwiththe youcouldopenit(byusingtheAppleScriptcom- addedbenefitthatthecallbacklanguageisleftup mand),andthenusetheOSAcommandtoopena totheuser’sdiscretion. connectiontotheUserLandcomponent... Itiscurrentlynotusefultoopenmultipleconnec- II) TclandtheOSA tionstothesamecomponent.Sincethecallsto theOSAcomponentsaresynchronous,havingsev- eralconnectionstoasingleOSAcomponentdoes TherearethreestepstofitTclintotheOSAarchi- notgainanything. tecture.ThefirstistoallowTcltousetheservices offeredbytheOSAcomponentsinstalledonthe system.ThisisthefunctionoftheTclOSAScript 2)CompilingandExecutingScripts: extensionwhichisdescribedintherestofthispa-

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us