Automating the Club Mailings
Here's the problem to be automated: When Don is mailing out the
newsletter, he wants to send special notices to members whose dues will
be due in the next month (or whose dues are already in arrears).
The rest of the membership get the standard email.
The chart below shows an abstract view of the process. The yellow
boxes represent address cards maintained by the Mail application. The red
lozenge represents the process that does the splitting. Ideally
that split could be accomplished by a smart
group in Address Book,
but the criteria on Anniversary
treat only the month and day and ignore the year!

Automator
The figure below shows the Automator
main window. Actions are dragged from the middle pane to the right pane
to form a sequence of actions. This interface presumes that data
flows along a single stream from top to bottom. (Which is not what our
diagram above shows.)

The actions associated with Address
Book are shown in the figure below. The gray bars to the
right of the actions indicate how likely it is that we want to use that
action.

However, the Group Mailer
action catches our eye. Its description, shown in the pane at lower
left of the full automator window, sounds promising.
This action sends a Mail message to multiple recipients.
Requires: An outgoing Mail message with subject, content and any attachments.
Input: (Address Book people)
Result: (Mail messages)
Related Actions: Send Outgoing Messages
Before we can use this action, we need to find a source of Address Book People. The
description of the top-rated action, Filter
Address Book Items, is not particularly helpful:
This action determines if the input items meet the specified criteria.
Input: (Address Book people)
Result: (Address Book people)
To get a more detailed view of its operation, we drag it to the right
pane and explore its interface:

The first disappointment is that we can't work with Anniversary; Birthday is the only date attribute
that the action recognizes. We're, of course, concerned that it will
treat in the same ignore-the-year fashion that Smart Groups do. To test it,
we add the View Results
action (from Automator
Library). We add birthdays to two address cards, one of 1/1/05
and the other of 1/1/06. After many complete failures, we
discover that the Find People in
Address Book is the one we really want. The figure below
shows the results:

It is apparent that the results we view are not easily comprehended,
but testing shows that this action behaves as we would like. The
only problem is that all our dates are stored in the Anniversary attribute. To
transfer the dates to Birthday
requires either tedium, Applescript, or editing vCards. It also is a
bit of a kludge to substitute Birthday for Anniversary.
The
Applescript action lets us work with the Anniversary attribute (but we have
to figure out that Anniversary
is the first item in a Custom Date
attribute.) The magenta text below is converted to a different
format when the script compiled (hammer icon). [Techniques for
developing and debugging Applescripts will be discussed below...]

We now feed the output of the Run
Applescript action into a Group
Mailer action. When we try to run this sequence, we get a
complaint that there is no outgoing message. Simply creating a
new message in Mail with
attachments does not satisfy the problem. Action New Mail Message seems to be
appropriate, but there isn't any way to add an attachment. That
leads to action Add Attachments to
Front Message. But that action requires Files/Folders as an input, not a Mail Message. So we add Ask for Finder Items. (Adding Send Outgoing Messages might be
appropriate in a well-tested product, but is otherwise embarassing.)


Upon running this sequence of actions, we get a set of email messages
addressed to those whose dues are due. Unfortunately, a similar
approach for the ordinary members is impractical because ~50 messages,
each with a large attachment, would be generated.

AppleScript
We have been only partially successful using Automator.
Applescript gives us much more flexibility. To set up, run the AppleScript Utility and select the
checkboxes as shown...

This will install a script menu near the right end of your main menubar.
Developing a script requires the vocablulary of the various
applications. In Script Editor
use the File menu to browse Address Book's dictionary.

Selecting an item in the application, and then running a simple
applescript (with Event Log
selected) is often a good beginning...

The full script splits the group into three: the ordinary group, those
with anniversary coming next month, and those overdue. In addition to
the attachment message, the latter get individual messages with their
anniversary date in the subject line.

