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 111
to recipients:"myboss@myCompany.com, hisboss@myCompany.com"
Now if you take a good look at the draft window entry in the dictionary, you will not discover any attachment property! Yet the code works. That is because the developers made a coercion to make things simpler: a putative property for use only at inception, in the with properties parameter of the make new draft window (or draft news window) or outgoing message commands. It doesn't work anywhere else. attachment is actually an element, not a property, of draft window and message classes, since there can be any number of them, from 0 to many.
If you want to get the attachments of an incoming or sent message, you can't get the attachment: you'll get an error. Instead you have to get attachments or every attachment of message, and then get the file property of each one if you want to track them down.
Getting back to our draft window (new message window), you could add the attachment after the fact this way:
set newMsg to make new draft window with properties {subject:"Today's File"}
make new attachment at newMsg with properties {file:alias filePath}
But if you have a lot of attachments to make, this would get tedious. Using the with properties parameter of make new draft window, you can attach a whole raft of attachments, using a list of aliases in { } list braces as the attachment property. You'll also notice we omitted a large number of draft window properties in our code: account, bounds, encoding, priority, and much else we didn‘t need to set. They all have default values, and do not need to be specified, but should we want to change any of them, we can do so.
Make a new Outgoing Message (in the background) and send it
Now how about really automating this process? If you have to send these documents as email attachments every day, and no special customized text message needs to be written each time, you can write a script to send it off all without interruptions of any kind; it's easy to do. Instead of making a draft window, make an outgoing message, and send it off without even bringing Entourage to the front – just stay in whatever application you're in.
Now if you look in the Entourage dictionary, you'll see that recipient is an element, not a property, of message (and of both its subclasses outgoing message and incoming message). That makes sense, since you can have several recipients (of all types, including To, CC, and BCC). And when you want to get the recipients of a message (incoming, or sent, for example), that's how you go about it: every recipient of theMsg . (We‘ll get into how you select the message a little later.) Then you delve into the recipient properties to get the email address and any display name – we'll get into that soon too.
You'd expect that when making a new outgoing message, you'd have to make each recipient at the new message just after making the message – the normal process for creating elements "at" an object. However, it can't be done with outgoing message. The reason is that once a message (as opposed to a draft window) is made, it's "encoded" for the Internet, and its internal structure cannot be modified. Fortunately, the developers again have implemented a coercion – another "putative" recipient property, just like the putative attachment property we've already seen.
Only this time it's essential: it's not a convenient alternative method – this time it's the only method. And it's not documented anywhere, except here. So make sure this one sinks in. Once again, it is only available at inception, when calling make new outgoing message with properties.
Both properties – address, recipient type – listed under recipient class in the dictionary – are available. The address property's type is the rather confusing address class, which in turn has another, different address (text) property – the actual email address – plus a display name text property as well If you are just sending to a single to recipient, you can omit a lot of the specifications, taking advantage of the fact that to recipient is the default recipient type, and you can also use a "Display Name <eaddress@domain>" shorthand (< > angle brackets around the email address) instead of the more complex recipient record structure. This handy coercion is also undocumented:
tell application "Microsoft Entourage"
launch -- in background
set theMsg to make new outgoing message with properties ¬
{subject:"Today's File", content:¬
"Please find today's .pdf file attached.", recipient:¬
"Joe Blow <joeblow@aol.com>", attachment:alias filePath}
send theMsg
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine