Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Page Prev and Page Next buttons at bottom of the page.
An Introduction to Entourage Scripting (No VBA Anywhere in Sight)
Why Entourage? You're probably already aware that Entourage, although a fully-fledged and important application in the Microsoft Office Mac suite, has never had VBA in the first place, so there's nothing to convert. Although Entourage corresponds quite closely to the role played by Outlook in Office Windows, it was never a port of Outlook to the Mac in the way that Word, Excel and PowerPoint are. (Actually, Word, Excel and PowerPoint were all originally on the Mac and in their earliest versions could be seen as being ported from Mac to Windows, but that's a story for another day. In their current incarnations, it works the other way around, with a Mac-oriented UI, modifications, adaptations, and Mac-specific features being added after receiving the shared part of the code – the core features – from the current Windows versions.)
Entourage, however, has always had an excellent AppleScript implementation. Now that you're becoming proficient in AppleScript, you suddenly have a whole new world open to you – actually, many new worlds; as many as there are AppleScriptable applications on the Mac.
Entourage shares many cross-Office features with the other Office applications, and has many useful features of its own. This article will give you just a short introduction to Entourage scripting as an example of how your AppleScript skills can now be extended and put to good use. In addition, a few useful techniques and implementations, plus one or two pitfalls to avoid, are described here that are not documented anywhere in the Entourage AppleScript dictionary nor anywhere else.
Finally, since Entourage has been scriptable for so long, there are already many scripts available for it – many can be found at MacScripter: <http://scriptbuilders.net>. You might find some there that already do exactly what you need. You‘ll also find a very large collection of open-source scripts from which to learn.
Entourage has a dictionary built on top of (and expanded from) the old Outlook Express Mac from Classic OS 8 (or maybe even 7.5) days. On the one hand, most of its syntax is a lot simpler and clearer than the other, rather contrived set from the other Office applications, and really does read more like English. On the other hand, the oldest part of the dictionary (non-Exchange email) is derived from the old OS 7 Apple Mail Suite, which had a few really odd quirks. The very newest parts of the dictionary (Exchange functionality) have a few quirks of their own.
Since Entourage does so many types of things, and makes so many different kinds of objects, this chapter will deal first with Email Messages, then Contacts & Groups, then Calendar Events & Tasks. (Notes will have to look after themselves.) Some scripts will overlap areas. We‘ll start by linking from the previous chapters – sending a document you made in Word, Excel, or PowerPoint as an attachment to an email message.
(All scripts in this chapter are my own: some published, some unpublished until now.)
Email: Make and Send a Message with an Attachment
You've just saved a document in Word, Excel or PowerPoint. Now you want to send it as an email attachment to someone. That's quite simple – just go to File/Send To/Mail Recipient (As Attachment). That brings up an empty email window in Entourage with the document already in place as an attachment. You then fill in the recipients, subject, write your message, and send. But if you regularly need to send such messages with attachments, every day, many times, always to the same recipients, this is going to get tedious very fast. Instead, write a script telling Entourage to do it all for you in a flash.
If you want to write a different message each time, the script can just switch you to Entourage with the attachment in place, the recipients already filled in, and the subject too, if you wish, and maybe a salutation ready for you to write the rest of the message. But if the message text can be "potted" as well, you can simply have the message prepared and sent off in the background without ever switching away from the application you're working in. We‘ll look at both cases.
The first step, in both cases, is to check that the document is saved – or save it – and to get its file path. This one step needs to be done in the application you're working from, and will be slightly different depending on whether that's Word, Excel or PowerPoint.
tell application "Microsoft Word"
set frontDoc to active document
< Previous Page Next Page>