Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 112
end tell
Note the first line: launch. If Entourage is already open in the background, this will do nothing. If Entourage is not open, this will launch it without bringing it to the front, as would happen if you omitted this line. (It's part of the AppleScript language, not Entourage, and works the same way for every application.) Note the simple recipient property value. (Since the script doesn't specify where to make it 'at', it does so in the local Drafts folder, the default location, using the default account. These properties can all be specified otherwise, of course, if you wish.) The file (alias filePath) in the attachment property depends on your having included the previous code to Word, Excel or PowerPoint to store the path of the saved front document as the variable filePath. The last line sends the message.
But the full syntax for recipient lets you specify as many recipients as you want, of whichever recipient types (to, cc, bcc) you want, by setting a list (in {} list braces) of all the recipients to the "putative" recipient property. You must also use record braces, which look the same, for each recipient, since each one is a record (containing address and recipient type properties) where each address is also a record (containing address and display name properties). That makes for a lot of braces:
tell application "Microsoft Entourage"
launch
set theMsg to make new outgoing message with properties ¬
{subject:"Today's File", content:¬
"Please find today's .pdf file attached.", recipient:¬
{{address:{address:"joeblow@aol.com", display name:¬
"Joe Blow"}, recipient type:to recipient}, {address:¬
{address:"janeblow@earthlink.com", display name:¬
"Jane Blow"}, recipient type:cc recipient}, {address:¬
{address:"scrooge@msn.com", display name:¬
"Ebenezer Scrooge"}, recipient type:¬
bcc recipient}}, attachment:alias filePath}
send theMsg
end tell
(That's just one recipient per type: you can include as many as you wish, of course, in the list. You can omit the recipient type if it's a to recipient, and you can omit display names.) And remember that when you write your own scripts you can ignore the line continuation marks and short lines used here so you won't get line-end errors if you copy and paste from an online source: any script editor will wrap long lines as needed.)
Once again, the filePath variable in the attachment property depends on your having included the previous code to Word, Excel or PowerPoint to store the path of the saved front document as this variable filePath. Just save the whole script (with both Word/Excel/PPT and Entourage code) in the system Script menu, and select it with your daily document in front, and off it goes to all those recipients without any activity or disturbance in your front application. You can also add a line of code to the Word/Excel/PPT block to close the active document (/workbook/presentation) saving yes, if you wish.
Now, when you first try to run this script or any other that sends a message, you will get a warning that "an external application is trying to send mail". Click to allow it, and if you are going to be doing much scripting of Entourage, also click to not warn you again. Better yet, go into Entourage/Preferences/Security and turn off both warnings about external applications trying to send mail and trying to access the address book, or you will get no end of these when trying to run scripts, which Entourage persists in considering as "external applications".
So far, there have been no malicious exploits reported for Entourage. On the Mac, as you probably know, there are no self-executing applications, so there is very low likelihood of your launching a malicious script, unless perhaps it is disguised as something else. [Ed. Note – it is something to be mindful of, and to take into consideration with your security policy if your company has one.][PB1]
Make a new outgoing message with more settings
In learning how to make a new message, we have been mostly concerned with recipients, since that is the tricky part. There are a great many other properties that can be set by script – in fact, everything that you can do in the UI (and then some). They are all very easy to script.
You might want to specify a different email account than your default account. Note: there is no generic "account" class, so you need to specify whether it is a POP account, IMAP account, Hotmail account, or Exchange account. Entourage is a database-based application, so virtually everything in it has a unique ID, and all references to elements (items) resolve to an ID reference, even accounts. (E.g., POP account id 1, IMAP account id 2, etc.)
But you won't usually know those. You can refer to almost everything in Entourage by its name, by its index if you know it, by its ID, or by a whose filter. The name of an account is not its email address (unless that's how you named it, which many people do), but the name you assigned it in Tools/Accounts/Mail. So usually you will refer to it by name as POP account "My Account" or whatever its name is.
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine