Assuming you know or can follow basic AppleScript syntax, what about scripting the Microsoft Office for Mac applications? If you know Visual Basic for Applications (VBA) for Microsoft Office for Windows, you're just about there already.
AppleScript and VBA have similar object models
The AppleScript Office 2004 object models for Microsoft Word, Excel, and PowerPoint are, for all intents and purposes, identical to that of their respective VBA object models. They really are the same object model, with a few differences endemic to the differing structures of the two languages, as described in detail in the next section.
AppleScript terms are all lowercase and can consist of several words, as opposed to VBA's portmanteau — capitalized, MultipleWordsSquishedTogether terms. For example, the Word VBA's AutoTextEntry object is the auto text entry class in AppleScript.
Because the object model provides a great many arguments to methods in VBA, which are parameters to commands in AppleScript, plus a great many enumerated constants (all those wdWhatever and xlThisOrThat constants) as values for these arguments, the syntax makes for quite a mouthful in AppleScript, where all these words run into each other without punctuation. Compare the following:
VBA |
|---|
ActiveDocument.SaveAs FileName:=myDocName, FileFormat:=wdFormatText |
AppleScript |
|---|
save as active document file name myDocName file format format text |
Here the command name save as is followed by its direct object active document without any punctuation. The two parameters, file name and file format, are each followed by a value. In the case of file name, it is followed by a variable,
myDocName. In the case of file format, it is followed by one of the enumerated values available to it, namely format text. All terms run on without punctuation.
Occasional differences in object models
Compare two other examples:
VBA |
|---|
temp = Options.DefaultFilePath(wdUserTemplatesPath) |
AppleScript |
|---|
set temp to get default file path file path type user templates path |
Note the departure from the VBA model in this example. In VBA, DefaultFilePath is a property of the Options object. In AppleScript, get default file path is a command with a file path type parameter, and user templates path is one of the enumerated values it can have.
Even regular AppleScripters may find some Office 2004 scripting constructions challenging.
There are no prepositions at the beginning of parameter names (or "–ing" participles on verbs) to improve readability.
At times, the enumerated values repeat words found in the parameter names, which in turn may repeat words found in the command name, and they seem to run together.
However, regular VBA scripters will be pleased to see familiar terms appearing in the AppleScript version, and will soon adapt to the lack of dots and other punctuation. Most Office VBA macro writers should become accustomed to Office AppleScript quite easily.


