

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 129
end tell
Note the where its instead of whose in the second line. In this case it is not optional, but mandatory: otherwise you will get an empty list {}. That is because Entourage, rather unfortunately, uses the same keyword 'category' both for this property of contact (and of other objects too) and also for the category class. (Every category you create in the UI or by script is a member of the category class.)
When used in a whose filter, AppleScript gets confused by the namespace conflict between a class and property of the same name, and gives priority to the class over the property. Since there are obviously no contacts which have the category class (they're all of contact class) the result is {} – always empty. But by using an equivalent formulation that includes the magic word its, thus pinpointing contact, not the application, as the container and category as its property, all becomes clear and you get the true result you're looking for. (You need to do the same thing when filtering on every message of some folder where its account is… .)
When the developers came to create the new class project in Entourage 2004, they had learned this lesson, and named the corresponding property of contact, event, etc. project list – so there is no conflict and you can use whose with abandon.
Also note the other pronoun my in the first line of the repeat block. That optimizes iterating through lists – by an enormous degree when the list is large. It can be dozens or hundreds of times faster, so use it. But it only works at the top level of a script, not in a handler unless you declare the list (categoryContacts) as a global variable at the top of the script in which you iterate in a handler. (There is also another method that can be used within handlers, requiring script objects: see the Neuburg book.)
Recipients Group (Make New Group)
Do you ever get email messages that were sent to a large number of recipients – perhaps from someone who sends out a newsletter? You might want to be able to email all the same people, as a group, yourself. Wouldn't it be nice if you could put all the recipients into a group in your Address Book so that you could send messages to the same set of people?
Entourage offers only "Add Sender to Address Book" from a rule or "Add to Address Book" when you click on a single name and address, one at a time – there's nothing for adding multiple recipients anywhere. This script will do it for you. First select the message in question, then run the script:
tell application "Microsoft Entourage"
display dialog "Enter a name for the group to be made from " & ¬
"the To recipients of selected messages:" default answer "" with icon 1
set groupName to text returned of result
display dialog "Do you want the group set to show " & ¬
"individual addresses or NOT show addresses in messages " & ¬
"to the group?" buttons {"Cancel", "Show addresses", ¬
"Don't show"} default button 3 with icon 1
if button returned of result = "Don't show" then
set showOnlyName to true
else
set showOnlyName to false
end if
set theGroup to make new group with properties ¬
{name:groupName, show only name in messages:showOnlyName}
set selectedMessages to (current messages)
set entryAddresses to {} -- initialize an empty list
repeat with i from 1 to (count selectedMessages)
set theMsg to item i of my selectedMessages
< Previous Page Next Page>

- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine