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 113
The message will appear automatically with the default signature you use for that account. So don't add it to the message content or it will appear twice. If you want to change it for this message, you need to change the default signature type and default signature choice of the account first (or to 'none' signature type and add the text you want to the message content) and then change it back after you make the message.
outgoing message is a subclass of the generic message class (with extra properties not sensible for received incoming messages), and inherits a few read-only properties that are appropriate only for (your own) messages after they are sent – such as forwarded, redirected, replied to, resent. Don't set them for a new message, even though most read-only properties can actually be set at inception if you really need to.
connection action is something only normally applicable to incoming POP messages. Probably it should have been made a property of incoming message class, not message. Don't try to set that for a new message either. edited really and truly is read-only and can't be set by script, ever.
color is a mistake, and is deprecated (inherited from Outlook Express). Don't try to set it: it's been replaced by category – each category has a color property which can be set. category property here is a list of categories {category "Work", category "Personal} since messages and other objects can have more than one category (the first one listed is primary and sets the color). Or it can be an empty list {} for no categories: there is no category "None"! The default is {} which does not need to be set.
Normally you will not set source, but you would if trying to duplicate another message (with perhaps a few differences which you set separately). source is the entire structured message text, parts, attachments, and headers. You wouldn't normally try to script headers either: let them be formed automatically.
All other properties can be set. has html could be set to true at inception – the default is false – but that just determines that your default HTML font and size will be used. Entourage does not have any way to script formatted text. And for some reason setting has html to true removes carriage returns from the message content, so don't do it.
Basically, stick to the properties marked in the dictionary as read-write. If you don't specify where to make the message, it gets made at your Drafts folder. The alternate location you might prefer to specify would be the outbox. Here's a typical example:
tell application "Microsoft Entourage"
-- add carriage returns before signature used for the account
set theBody to "Some long text here. As long as you want." & return & return
set theMsg to make new outgoing message at outbox folder with properties ¬
{account:POP account "My Account", subject:"My New Message", content:¬
theBody, recipient:"Joe Blow <jblow@aol.com", flagged:¬
true, priority:high, category:{category "Work"}}
end tell
Make an incoming message
You might wonder what would be the point of making a new incoming message, since those are messages you receive from others. You wouldn't think it would even be possible. In fact, it's a way of importing messages into Entourage. (The import command is so far just valid for .mbox files, which become message folders.)
You could read the content of an .eml message file, in a way similar to reading a .vcf file in “Attach a vCard” later in this chapter, and use that as the source property – the only property you'll need – to make a new incoming message at any folder. Or to make a duplicate message from properties of an existing message at a location where duplicate does not work.
The interesting thing is that this is possible by AppleScript, although not in the UI. Most of the so-called read-only properties are settable at inception, so you can do almost whatever you want with the power of AppleScript. Just follow the same sort of procedure as making an outgoing message, but do it as an incoming message, to see for yourself.
Email: Selecting Messages, Running Scripts from Rules, Schedules, Menus
Sometimes the email scripts you run will be on received messages. You may have seen that Entourage's Rules (in Tools menu) can be enabled to run automatically on messages as they come into the Inbox, and one of the possible Actions they can perform is to Run AppleScript. Similarly, Schedules (also in the Tools menu) can be set to perform tasks on a regular repeated schedule, or at startup or on quit, and can also Run AppleScript. Both of these provide a very high degree of customization and automation, since AppleScript can do "almost anything" with Entourage's objects, far more than standard Rule and Schedule actions can do, and also with a far finer degree of selection and combination.
You may have found a certain degree of frustration with rules that let you filter when "all criteria are met" (i.e., boolean AND for all conditions) or when "any criteria are met" (i.e., boolean OR for all conditions) but no finer or more complex granularity: AppleScript can handle any degree of complexity, so just write it as a script and run the script from the rule.
Before we get to some more examples, there's one thing, not fully explained in the Entourage dictionary, that needs to be dealt with. It will come up again and again in your Entourage scripts. How do you specify the selected message(s) on which you want to run a script, and how do you specify the message on which the running rule should operate? By the same application property – current messages – which is always a list of messages.
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine