Tải bản đầy đủ (.pdf) (974 trang)

OReilly applescript in a nutshell jun 2001 ISBN 1565928415

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.97 MB, 974 trang )




Tableof

Contents
• Index
• Reviews
• Examples
Reader

Reviews
• Errata

AppleScriptinaNutshell
ByBruceW.Perry

Publisher :O'Reilly
PubDate :June2001
ISBN :1-56592-841-5
Pages :526
Slots :1



AppleScriptinaNutshellisthefirstcompletereferenceto
AppleScript,thepopularprogramminglanguagethatgives
bothpowerusersandsophisticatedenterprisecustomers
theimportantabilitytoautomaterepetitivetasksand
customizeapplications.AppleScriptinaNutshellisahighendhandbookatalow-endprice--anessentialdesktop
referencethatputsthefullpowerofthisuser-friendly


programminglanguageintoeveryAppleScriptuser's
hands.





Tableof

Contents
• Index
• Reviews
• Examples
Reader

Reviews
• Errata



Copyright



Preface

AppleScriptinaNutshell
ByBruceW.Perry

Publisher :O'Reilly

PubDate :June2001
ISBN :1-56592-841-5
Pages :526
Slots :1



OrganizationofThisBook



ConventionsUsedinThisBook



HowtoContactUs



Acknowledgments





PartI:IntroductiontoAppleScript
Chapter1.AppleScript:AnIntroduction




Section1.1.HowIsAppleScriptUsed?



Section1.2.AppleEvents



Section1.3.UsingScriptRunnerwithOSX



Section1.4.UsingOSAMenuwithOS9



Section1.5.CheckingYourAppleScriptVersion



Section1.6.DivingIn




Chapter2.UsingScriptEditorwithOS9andOSX



Section2.1.ScriptEditorControls/Commands




Section2.2.ScriptingtheScriptEditor







PartII:AppleScriptLanguageReference
Chapter3.DataTypes
alias






boolean



class



constant




data



date



filespecification



integer



internationaltext



list



number




real



record



reference



RGBcolor



string



StyledClipboardText



StyledText



text




UnicodeText



UnitofMeasurementClasses




Chapter4.Operators



&



()



*



+




-



/÷div



<



<=



=



>



>=



^




[a]referenceto



and



as



begin[s]with



contains



doesnotcontain



doesnotequal




endswith



iscontainedby




isnotcontainedby



mod



not



or




Chapter5.ReferenceForms




after



back



before



beginning



first,second,third,fourth,etc.



every



every...from...to...



id




last



middle



name



some



whose




Chapter6.VariablesandConstants



Section6.1.Variables




Section6.2.ConstantsandPredefinedVariables




Chapter7.Flow-ControlStatements



considering[butignoring]end[considering]



continue



error



exit[repeat]



ifsimplestatement




if[then][elseif][else]end[if]



ignoring[butconsidering]end[ignoring]



repeatend[repeat]



repeatuntilend[repeat]



repeatwhileend[repeat]





repeatwith{loopvariable}from{integer}to{integer}[bystepVal]end
[repeat]



repeatwith{loopvariable}in{list}end[repeat]




repeat{integer}timesend[repeat]



return[returnvalue]



tellsimplestatement



tellend[tell]



try[onerror][number|from|partialresult|to]end[error|try]



usingtermsfromend[usingtermsfrom]




withtimeout[of]{integer}second[s]end[timeout]




withtransaction[sessionobject]end[transaction]




Chapter8.Subroutines



Section8.1.SubroutineswithPositionalParameters



Section8.2.SubroutineswithLabeledParameters




Chapter9.ScriptObjectsandLibraries



ScriptObjects



Libraries







PartIII:ScriptingMacOS9Applications
Chapter10.AppleGuideandHelpViewer



AppleGuide



HelpViewer





Chapter11.AppleSystemProfiler
AppleSystemProfiler




Chapter12.KeychainScriptingandAppleVerifier



KeychainScripting




AppleVerifier





Chapter13.DesktopPrinterManager
DesktopPrintManager





Chapter14.MacOS9FinderCommands
Section14.1.ExampleFinderScripts





Chapter15.MacOS9FinderClasses
FinderClasses






Chapter16.NetworkSetupScripting
NetworkSetupScripting





Chapter17.ScriptingSherlock2
Sherlock2






Chapter18.URLAccessScripting
URLAccessScripting








PartIV:ScriptingMacOS9ControlPanelsandExtensions
Chapter19.AppearanceControlPanel
AppearanceControlPanel






Chapter20.AppleDataDetectorsExtension
AppleDataDetectors





Chapter21.AppleMenuOptionsControlPanel
AppleMenuOptions





Chapter22.ApplicationSwitcherExtension
ApplicationSwitcher





Chapter23.ColorSyncExtension
ColorSync






Chapter24.FileExchangeControlPanel
FileExchange





Chapter25.FileSharingControlPanel
FileSharing





Chapter26.FolderActionsExtension
FolderActions




Chapter27.FontSyncControlPanelandExtension



FontSyncControlPanel



FontSyncExtension






Chapter28.LocationManagerControlPanel
LocationManager




Chapter29.MemoryandMouseControlPanels



MemoryControlPanel



MouseControlPanel




Chapter30.SpeechListenerandSpeakableItemsExtension



SpeechListenerApplication




SpeakableItemsExtension



EmbeddedSpeechCommands






Chapter31.WebSharingControlPanel






PartV:ScriptingtheMacOSXSystem
Chapter32.ScriptingtheOSXDesktop
Section32.1.WorkingwithFiles,Folders,Disks,andWindowsinOSX




Chapter33.ScriptingMail




Section33.1.SettingUpanEmailMessage



Section33.2.ExploringtheMailApplicationObject



Section33.3.GettingInformationaboutanEmailAccount




Chapter34.ExecutingScriptswiththeTerminalApp



osacompile



osalang



osascript






Chapter35.ScriptingTextEdit
TextEdit






PartVI:Appendixes
AppendixA.StandardScriptingAdditions



StandardAdditions



StandardAdditions




AppendixB.AppleScriptResources



SectionB.1.AppleComputerAppleScriptURLs




SectionB.2.AppleScriptFAQs,MailingLists,andTutorials



SectionB.3.MacintoshScriptingSites



SectionB.4.CommercialAppleScriptDevelopmentEnvironments



SectionB.5.FreewareAppleScriptDevelopmentEnvironments





Colophon



Index


Copyright©2002O'Reilly&Associates,Inc.Allrightsreserved.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'Reilly&Associates,Inc.,101MorrisStreet,Sebastopol,

CA95472.
NutshellHandbook,theNutshellHandbooklogo,andtheO'Reillylogo
areregisteredtrademarksofO'Reilly&Associates,Inc.Manyofthe
designationsusedbymanufacturersandsellerstodistinguishtheir
productsareclaimedastrademarks.Wherethosedesignationsappearin
thisbook,andO'Reilly&Associates,Inc.wasawareofatrademark
claim,thedesignationshavebeenprintedincapsorinitialcaps.The
associationoftheimageofaBostonterrierandthetopicofAppleScriptis
atrademarkofO'Reilly&Associates,Inc.
AppleComputer,Inc.boldlycombinedopensourcetechnologieswithits
ownprogrammingeffortstocreateMacOSX,oneofthemostversatile
andstableoperatingsystemsnowavailable.Inthesamespirit,Applehas
joinedforceswithO'Reilly&Associatestobringyouanindispensable
collectionoftechnicalpublications.TheADClogoindicatesthatthebook
hasbeentechnicallyreviewedbyAppleengineersandisrecommended
bytheAppleDeveloperConnection.
Apple,Macintosh,AppleScript,MacOS,andMacOSXareregistered
trademarksofApple,Inc.
Whileeveryprecautionhasbeentakeninthepreparationofthisbook,
thepublisherassumesnoresponsibilityforerrorsoromissions,orfor
damagesresultingfromtheuseoftheinformationcontainedherein.


Preface
AppleScriptcontinuestoevolveonMacOS9andMacOSXasthe
ultimatescriptingtoolfortheMacintosh.AppleScript'spowertoautomate
theoperatingsystemandcomplexapplicationssuchasgraphics,
desktop-publishing,anddatabaseprograms,aswellasafriendlyEnglish
languagedialectthathelpsambitiousscriptersgetuptospeedquickly
withtheirownapplets,isnotmatchedbyanyotherplatform's

programminglanguage.Yet,onlyasmallpercentageofMacintoshusers
areevenawarethatAppleScriptisinstalledwiththeiroperatingsystem.
ThosewhoareawareofAppleScript'spresenceontheirmachineoften
donottakefulladvantageofthistooltoautomatetheirdailycomputing
activities,bothontheirlocalmachineandovertheInternet.
WhoshouldandcanuseAppleScript?Thefollowinguserscometomind
rightaway:systemadministratorswhoareautomatingtaskswith
networksandapplications;webandgraphicsprofessionalswhowantto
controlthedevelopmentofwebsitesandpublications;scientists,
mathematicians,andengineerswhorequireappletstomakecalculations
andautomatetheirownsoftwaretools,aswellasday-to-day
programmersandstudentswhoaredesigningandprototypingnew
programs.Nottomentioneverdayuserswhowanttoautomatetheirown
computingtasks,suchasfileandfolderbackups.
IfyouareonaMacintosh,thenyoushouldbeputtingAppleScripttowork
foryou.
Thepurposeofthisbookisprimarilythree-fold:
1. DescribeAppleScriptanditstools(PartI)andprovideacore
languagereference(PartII)thatalluserscankeepnexttotheir
computersastheywritenewscripts.
Providedetaileddescriptions,examples,andreferenceinformationon
howtoscriptthenumeroussystem-levelprogramsonMacOS9(PartIII
andPartIV)andMacOSX(PartV),suchastheFinderonbothOS


versions,Sherlock,andNetworkSetupScripting.
Givescriptersgeneralinsightonhowtoapproachthescriptingof
severalprogramsthatcanbeautomatedbyAppleScript,suchasAdobe
IllustratorandPhotoshop,FileMakerPro,QuarkXPress,SoundJamMP,
andOutLookExpress.Themantrais,studythe"applicationclass"inthe

program'sAppleScriptdictionaryandyou'llbeupandrunningwith
scriptingthatprogrambeforeyouknowit.(Chapter1discussesthe
applicationclassingeneralterms;whiletheapplicationclassesofallthe
varioussystemcomponentsaredescribedindetailthroughoutthebook.)
Hopefully,thisbookwillhelprevealAppleScripttomoreMacintoshusers,
thusprovidingthemwithanotheroutletforcreativityandproductivity.


OrganizationofThisBook
AppleScriptinaNutshellisstructuredinsixparts.

PartI
ThissectionprovidesanoverviewofAppleScriptandScriptEditor,the
freeAppleScriptdevelopmenttoolthatinstallswiththeMacintosh.Quick
studiesandexperiencedprogrammerswillprobablybeabletodevelop
theirfirstAppleScripts(ifyouhaveneverusedAppleScriptbefore)based
onareadingofthisintroductorysectionalone.Chapter1describeshow
AppleScriptisprimarilyusedandalsodescribestherelevanceto
AppleScriptofAppleevents,aninternalmessagingsystemthatthe
Macintoshoperatingsystemusesforinterapplicationcommunication.
TheendofChapter1summarizesAppleScript'scorelanguagefeatures
(PartIIprovidesamorecomprehensivelanguagereference).Youcan
useChapter2asahelpfulreferencetoScriptEditorasyouusethis
AppleComputertooltodevelopyourscripts.
Chapter1
ThisAppleScriptoverviewincludesadescriptionofhowAppleScriptis
primarilyused,anApple-eventtutorial,andacompressedlanguage
referenceforthosewhowanttodiverightintoscripting.Noviceusers
shouldstartherewiththebook,whileveryexperiencedAppleScripters
mayusethissectionasarevieworskipoverit.

Chapter2
ThischapterdescribesallofScriptEditor'sprimarymenucommandsand
controls.ItalsoexplainsthevariousoptionsforsavingAppleScriptfiles.

PartII


Ifscriptersneedmoreinformationonspecificlanguagefeatures,thisis
theplacetolook.Thecore-languageinformationispresentedwithsyntax
examples,codeexamples,andtextdescriptions.Everythingisarranged
inalphabeticalordertomakethingseasytolocate.Thisincludesthe
variousdatatypes(i.e.,howAppleScriptstoresdatainmemory),
operators(suchasthecommonMathoperatorsandthestringconcatenationoperator"&"),andhowtosetAppleScriptvariablesand
createuser-definedfunctions,aswellasadvancedfeatures,suchas
creatingobject-orientedscriptobjects(Chapter9).
Chapter3
Thischapterdescribesthebuilt-inAppleScriptdatatypes,including
string,integer,real,list,andrecord.Comparisonswith
programminglanguagesaremadewhereitisappropriate(e.g.,alistis
likeanarray,andarecordisanassociativearray).
Chapter4
Usethischapterasareferencetothebuilt-insymbols(e.g.,&,+,*,-)
thatyoucanuseinAppleScriptexpressions.
Chapter5
AppleScriptprovidesseveralEnglish-languagetermstousewhenthe
scriptreferstoobjectsonyourcomputersystem,suchasfiles,folders,
disks,andapplications.Thischapterisanalphabeticalreferencetothese
terms(e.g.,first,every,id,where).
Chapter6
AppleScript,likeotherlanguages,usesvariablesasplaceholdersthat

representdata(e.g.,stringsornumbers).Thischapterdescribesthe
rulesfornamingandcreatingyourownvariables;italsoprovidesa


referencetoAppleScript'sconstantsandpredefinedvariables(likepi).
Chapter7
ThischapterisanalphabeticalreferencetoAppleScript'sflow-control
statements,suchasif,repeat,try,exit,andcontinue.
Chapter8
Thischapterisatutorialoncreatinguser-definedsubroutines,whichare
alsocalledhandlers,functions,ormethods(inobject-orientedparlance).
Thesecondpartofthischapterdescribesfivespecialhandlersin
AppleScript:idle,open,quit,reopen,andrun.
Chapter9
AppleScripterscancreatescriptobjects,whichareuser-definedtypes
thatcanhavetheirownattributesandmethods.Thischapteralso
describesfunctionlibraries,whicharescriptobjectsthatgiveother
externalscriptstheabilitytoloadand/orcalltheobject'sownfunctions.

PartIII
Thissectionisdevotedtothescriptingofsystem-levelMacOS9
programs,suchasAppleSystemProfiler,KeychainScripting,theFinder,
NetworkSetupScripting,andSherlock2.Thescriptablecontrolpanels
andextensionsarecoveredinthenextsection,PartIV.Theprograms
thatarecoveredinthissectionforthemostparthavecomprehensive
AppleScriptdictionariesandcanbeusedtoextendyourcomputer's
capabilities(particularlywithAppleScript!);however;theyarenotcontrol
panelsorextensions.TheexceptiontothisschemeisAppleGuide,
whichisanextensionbutwasincludedinthissectionsothatthereader
hasaccessinasinglechaptertoadescriptionofAppleScriptandthe

help-relatedprograms.Eachchapterdescribesthepurposeofthe


application,thendescribeseachdictionarycommandandclassina
reference-styleform.
Chapter10
Thischapterdescribesthedictionariesandincludesscriptingtipsfor
AppleGuide,thetraditionalautomatedApple-helpprogram,andthe
newerbrowser-basedHelpViewertool.
Chapter11
AccessiblefromtheApplemenu,AppleSystemProfilerdisplaysawealth
ofinformationaboutthehardwareandsoftwareonyoursystem.This
chapterdescribesitscommandsandclassesandincludesnumerous
codeexamples.
Chapter12
ThesearetwoApple-securitytools.KeychainScriptingisusedtoencrypt
filesandpasswords,andAppleVerifiercanverifydigitally-signedfiles.
Thischaptertellswheretofindtheseapplicationsanddescribestheir
commandsandclassesinreferenceform.
Chapter13
ScripterscanuseDesktopPrinterManager,aprogramintroducedwith
MacOS8.5,tocreateandmanagedesktopiconsthatcanbeusedfor
printingorotherwiseprocessingdocumentsandfiles.Thischapter
describesthepropersyntaxforcontrollingthisapplicationwith
AppleScriptandalsoincludesareferencetoitsdictionarycommandsand
classes.
Chapter14


TheFinderistheMacOS9applicationthatcontrolstheuser'svisual

interfacetothecomputer:itsdesktopcontrolsaswellasharddisks,
networkvolumes,printers,andotherdevices.Alotoffunanduseful
AppleScriptsdealwithautomatingFinderactivities,suchasreadingfrom
andwritingtofiles.ThischaptercoverstheFindercommands,like
restart,shutdown,sleep,andmake,withdetailedreferencestoeach
commandandanyoftheirparameters.
Chapter15
ThischaptercoverstheFinderclasses,whicharealltheobjectsorthings
youarelikelytocontrolwhenscriptingtheFinder(e.g.,files,folders,
disks,andrunningapplications).FinderClassesprovidesadetailed
referencetoeachobject'selements(ifany)andproperties.
Chapter16
AstheMacintoshbecomesasophisticatedclientandserveronTCP/IP
networks,NetworkSetupScriptingshowshowyoucanusethe
commandsandclassesofthisprogramwithOpenTransporttoscripta
machine'svariousnetworkconfigurations.
Chapter17
YoucanautomatesophisticatedsearchesoflocalnetworksandtheWeb
withAppleScriptandSherlock2.ScriptingSherlock2providesa
descriptionofthisprogramandareference,withcodeexamples,toits
commands(e.g.,indexcontainers,search)andclasses.
Chapter18
URLAccessScriptingdescribesthedownloadanduploadcommandsof
thisprogram,whichcanbeusedwiththeFTPandHTTPprotocolsto
grabandsavefilesofftheWeb.


PartIV
ThissectionisdedicatedtothescriptingoftheMac'scontrolpanelsand
extensions,whicharelocatedintheControlPanelsandExtensions

foldersoftheSystemFolder.Eachchapterdescribesthepurposeofthis
systemsoftware,thenincludesareferencetotheirdictionarycommands
andclasses.Someofthemoreexcitingnewscriptabletechnologiesare
includedinthissection,includingAppleDataDetectors,FolderActions,
andtheSpeech-relatedextensionsinChapter30.
Chapter19
ThisscriptablecontrolpanelletsyouuseAppleScripttosetandchange
thevisualandaudibleaspectsofyourcomputer,suchasitsbackground
color,thefontfordesktoptext,andhowwindowtitlebarsandscrollbars
work.Weshowyouhowtodothisandincludeadetailedreferenceto
thissoftware'scommandsandclasses.
Chapter20
Thischapterdescribesapowerfulscriptingtechnologybywhichyoucan
assignanAppleScripttobetriggeredbasedoncertaininformationthata
userselectsinsideofacontextualmenu,suchasanemailorweb
address.AppleDataDetectorsExtensiondescribestheAppleData
Detectorsscripting-additionclassandcommandsinreferenceform.
Chapter21
ThischapterdescribeshowtouseAppleScripttoautomatevariousmenu
items(e.g.,Recentapplications,documents,andservers)intheApple
menu(thedrop-downmenuintheupper-leftpartofthecomputer
screen).
Chapter22


TheApplicationSwitcheristhefloatingpalettethattheusercan"tear"off
oftheApplicationmenu(ontheupper-rightpartofthecomputerscreen).
ThischapterdescribeshowtosetvariousSwitcherelements(e.g.,its
size,position,buttonorder)withAppleScriptandincludesareferenceto
itsextensiveapplicationclass.

Chapter23
ColorSyncExtensiondescribestheAppleScriptcommandsandclasses
forthisbuilt-inMacintoshsoftware,whichhelpssynchronizecolormatchingbetweenthedevicesthatcreateanimage(e.g.,scanners)and
printers.
Chapter24
ThischapterdescribestheFileExchangecommandsthatyoucanuseto
createnewextensionmappings(i.e.,awaytotelltheMacintoshhowto
handlefileswithcertainextensionslike.html),forinstance,orviewthe
existingfile-typemappingsonamachine.
Chapter25
ThischapterfirstsummarizesfilesharingontheMacintosh,which
establishesthelevelofaccessnetworkusershavetoamachine'sdisks
andfolders.Thenitshowshowtocreatenewusersorgroups(ordelete
miscreants)withcodeexamplesandareferencesectiononFile
Sharing'sdictionarycommandsandclasses.
Chapter26
FolderactionsareAppleScriptsthataretriggeredwhenitemsareadded
toorremovedfromafolder.Folderactioncommandsconstitutethe
FolderActionssuiteoftheStandardAdditionsosaxandthedictionary
commandsthatderivefromtheFolderActionsextension.Thischapter


describesbothsetsofcommands.
Chapter27
ThischapterdescribesthedictionariesfortheFontSynccontrolpanel
andextension.Theyareusedtosynchronizethefontsbetweendevices
duringimageproductionandprinting.
Chapter28
ThischaptershowshowyoucanuseAppleScripttoswitchbetweenthe
variouscomputerandnetworkingconfigurationsthataredisplayedbythe

LocationManagercontrolpanel.
Chapter29
Thischapterdescribesthedictionarycommandsandclassesforboththe
MemoryandMousecontrolpanels.Forexample,thechaptershowshow
youcanuseanapplettofindoutaboutthecomputer'svirtual-memory
settingsordisk-cachesize.
Chapter30
Thischapterdescribesthedifferentwaysthatyoucanintegratespeech
intoyourscripts,suchasthelistenforandsayAppleScriptcommands.
SpeechlistenerisactuallyanapplicationthatislocatedintheScripting
AdditionsfolderoftheSystemFolder,butitwillnotworkunlessthe
SpeechRecognitionextensionisinstalledandenabled.
Chapter31
ThischapterdescribesthefunctionalityoftheWebSharingcontrolpanel
andalsogivesanexampleofhowtouseAppleScriptwithaCommon


GatewayInterface(CGI)script.CGIscriptsexecuteinresponsetoweb
pagerequests,inordertoprocesstheincomingdatafromaformaweb
userhasfilledout,forinstance.TheWebSharingcontrolpanelcanbe
usedtoallowacomputertoperformasalight-weightwebserver.

PartV
AppleScriptisinastateoffluxandevolutiononthenewMacOSX
system.AppleScriptalsofacestremendouscompetitionfromthe
programmingtoolsthatcomewith(andcanbeinstalledon)MacOSX,
suchasshellscriptingtools,Perl,andJava.Nevertheless,thissection
willdescribewhatyoucandowithAppleScriptandthreeMacOSX
programsthatcanbeusedwithAppleScript:Mail,Terminalapplication(a
command-linetool),andTextEdit.PartVbeginswithadiscussionof

AppleScriptandscriptingthenewMacOSXFinder,whichistheOS9
Finderafteramajorfacelift.
Chapter32
ThischapterexplainssomeofthefamiliarFinder-likescriptingthatyou
canaccomplishonMacOSX,suchasgettinginformationaboutdesktop
items(e.g.,files,folders,anddisks)andmakingnewfiles.Thischapter
comparestheMacOSXFinderdictionarytotheMacOS9Finder
dictionary(andfindsfewdifferences,butthatislikelytochangewithnew
OSXversions).
Chapter33
ThischapterdescribestheuseofAppleScriptwithAppleComputer'snew
emailapplication,aptlycalled"Mail."Thischapterprovidesdescriptions
andcodeexamplesonsettingupanewmailmessageandgetting
informationaboutanemailaccount.
Chapter34


Terminalapplicationisthecommand-linetoolorinterface(awindowor
shellthatyoutypescriptcommandsinto)thatcomeswithMacOSX.
Thischaptershowshowyoucancreate,compile,andexecute
AppleScriptsfromtheTerminalprogram.
Chapter35
ItislikelythattheTextEdit'savailableAppleScriptcommandswillchange
withnewMacOSXreleases,sothischapterfocusesonTextEdit'smajor
commands(e.g.,count,open,save)andtext-relatedclasses,suchas
character,document,paragraph,andtext.

PartVI
OurAppleScriptbookwouldnotbecompletewithoutadescriptionand
referenceinformationonthemanyscriptingadditionsor"osaxen"that

veteranscriptersuseinalmosteveryscript(rememberdisplaydialogor
currentdate?).AppendixAcoverstheStandardAdditions(agroupof
scriptingadditionsthatAppleComputerbundleswiththeOSinstallation)
thatareinstalledwithbothMacOS9andMacOSX.Thissection
describeseachoftheStandardAdditions(e.g.,ASCIInumber,beep,
chooseapplication)andanyparametersthattheseosaxcommandsuse.
AppendixB,isalistofURLsthatarerelevanttoAppleScriptusers.
AppendixA
ThisappendixfocusesontheseveraldozenStandardAdditionscripting
additions,whichareinstalledalongwithMacOS9andMacOSX.These
areextensionstothebuilt-inAppleScriptcommandsthatyoucanuse
virtuallyanywhereinyourscript(Chapter1alsodiscussesscripting
additions).TheStandardAdditionsarelocatedinthestartupdisk:System
Folder:ScriptingAdditionsfolderinOS9and,withMacOSX,
/System/Library/ScriptingAdditions/(theprimarylocationonOSX).


AppendixB
ThisisanextensivelistofwebpagesrelatingtoMacintoshscriptingand
AppleScript.


ConventionsUsedinThisBook
Thefollowitypographicalconventionsareusedinthisbook:
Constantwidth
Isusedtoindicatecommand-linecomputeroutputandcode
examples,aswellasAppleScriptclassnames,objects,parameters,
datatypes,properties,methods,constants,variables,andflowcontrolstatementslikerepeat.
Constantwidthbold
Isusedtoindicateuserinputinexamples.

Italic
IsusedtointroducenewtermsandtoindicateURLs,user-defined
filesanddirectories,commands,fileextensions,filenames,directory
orfoldernames,andUNCpathnames.
Italicisalsousedtohighlightchaptertitlesand,insomeinstances,
tovisuallyseparatethetopicofalist.
Thisisanexampleofanote,whichsignifiesvaluableand
timesavinginformation.

Thisisanexampleofawarning,whichalertstoapotential
pitfallintheprogram.Warningscanalsorefertoaprocedure
thatmightbedangerousifnotcarriedoutinaspecificway.

KeyboardShortcuts


Whenkeyboardshortcutsareshown(Command-N),ahyphen
meansthatthekeysmustbehelddownsimultaneously,whileaplus
meansthatthekeysshouldbepressedsequentially.
PathNotation
Weuseashorthandpathnotationtoshowyouhowtoreachagiven
userinterfaceelementoroption.Thepathnotationisrelativetoa
well-knownlocation.Forexample,thefollowingpath:
ScriptEditor'sFile

OpenDictionary

means"OpentheScriptEditor'sFilemenu,thenchooseOpen
Dictionary."
Filepathdelimiters

AppleScriptusesthecolontoseparatethedirectoriesinafilepath,
asinMyStartupDisk:DesktopFolder:myfile.Themajorscripting
additionsthatdealwithfilepaths,suchaschoosefile,choosefile
name(MacOSXandOS9.1),choosefolder,andpathto,display
theirfilepathsinaliasreturnvaluesascolons.Thechaptersthat
dealwithMacOSX,however,willoftenidentifythelocationsoffiles
andfolderswiththeUnix-styleslashcharacter/asthepath
delimiter(e.g.,/users/bruceper/documents/).Thisisthepath
delimiterusedbyDarwin,whichisthecoreoperatingsystemforMac
OSXandhasUnixorigins.Theopeningslashcharacterinthefile
path/users/bruceper/setsthebeginningofthepathtothe"users"
folderonthediskorpartitionwhereMacOSXislocated.
AppleScriptonMacOSXstillgenerallyusescolonsasthepath
delimiter,however,whichmaintainsconsistencywitholderscripts
(OS8/9).Oneplacewhereyoucanusetheslashcharactertolocate
apathforAppleScriptisinsettingthetargetpropertyforaFinder
window,asin:
setthetargetofFinderwindow1to"/users/bruceper/"
ItalicConstantWidth


Onoccasion,youwillfindacommanddescriptionsuchasconnect
remoteaccessconfigurationobject,whichmeansthatthe
connectcommandtakesaremoteaccessconfiguration
objectasaparameter.


HowtoContactUs
Wehavetestedandverifiedtheinformationinthisbooktothebestofour
ability,butyoumayfindthatfeatureshavechanged(oreventhatwe

havemademistakes!).Pleaseletusknowaboutanyerrorsyoufind,as
wellasyoursuggestionsforfutureeditions,bywritingto:
O'Reilly&Associates,Inc.
101MorrisStreet
Sebastopol,CA95472
1-800-998-9938(intheU.S.orCanada)
1-707-829-0515(international/local)
1-707-829-0104(FAX)
Youcanalsosendusmessageselectronically.Tobeputonthemailing
listorrequestacatalog,sendemailto:

Toasktechnicalquestionsorcommentonthebook,sendemailto:

Wehaveawebsiteforthebook,wherewe'lllistexamples,errata,and
anyplansforfutureeditions.Youcanaccessthispageat:
/>Formoreinformationaboutthisbookandothers,seetheO'Reillyweb
site:



×