Thanks, for your thoughtful illustration, Paul. I didn't include previous
code because I've tried about a thousand versions, departing from the
original MS-provided script for Excel at
http://www.microsoft.com/mac/resources/resources.aspx?pid=asforoffice. I
have been able to return a list of lists, in which each record is showing
the category property to be a list and I did see the dictionary entry
showing the property to be a list, which is unusual indeed. Such as:
{{category id 11 of application "Microsoft Entourage"}, {}, {category id 19
of application "Microsoft Entourage"}, {}, {}}
That's a list of lists. I can only imagine that it must be the result of
asking for
category of every contact [whose something is something]
You weren't asking here for the contacts, but for their categories. Whenever
you ask for a [singular] property of every element , with o with a whose
clause, the result result is a [plural] list containing that property
iterated over each element. So you get a list. Since the property in
question here is 'category', which is itself a list, so you get a list of
lists. Any contact which has no category (seen as "None" in the UI) does not
have a "None" category; it has an empty list, namely {} - accounting for
those {} in the outer list.
I was close at one point, using "where" rather than "where its" so I'll get
back to it. Thanks again. I'm trying to work this out so that I can use the
name rather than the unique ID of the category.
Although elements can be specified by various ways - the dictionary tells
you which - in most cases by name, by index, relative to another, and by a
whose filter - the "true" specification is by ID. In other words, since even
the name of an element can be changed (set) without the object losing its
"whatness", the solid way to identity something is by ID: only rebuilding
the database loses the ID. So that's why Entourage's AppleScript always
returns results using id numbers where possible. (One of the few exceptions
is for group entries - members of a group - known only by index, which can
change. Same with email addresses of a contact.)
So if you want to get the name of every POP account, say, rather than the
IDs, you'd ask for
name of every POP account
and that's what you'd get. You can also ask for
name of every category
meaning category as element of the application. If you do that, you'll get a
list of all your categories by name. (You'll notice again that there is no
such category called "None".)
But since 1) category of a contact is a list and 2) some contacts have no
category, there's no way of getting the 'name of category of every contact',
since there's no such thing. If there was any reason, you could get that
list of 'category of every contact [where its...]', and then iterate through
the list getting 'name of item 1' for each item of the list - but you'd need
an error handler for cases where the category is {} since in that case
there's no item 1. Something like this:
set theContactCategories to category of every contact ...[whose
something is something]
set primeNames to {}
repeat with i from 1 to (count theContactCategories)
set theCatList to item i of theContactCategories
try
set end of primeNames to name of item 1 of theCatList
on error
set end of primeNames to "None"
end try
end repeat
return primeNames
Or if you'd rather you could use
if theCatList ‚ {} then
set end of primeNames to name of item 1 of theCatList
else
set end of primeNames to "None"
end if
which does the same thing (a little slower).
(By the way, I trust you realize why the 'category' property of a contact
has to be of type list: a contact can have several categories. The
AppleScript list will always be in the same list order as in the UI, which
means that item 1 is always the Primary category - the one that displays the
color in the UI.)
Now that you know how to filter contacts by category using 'where its', you
probably won't need to do this at all. You can always refer to the category
you're filtering on by name - you don't need to know the ID. Entourage will
find the ID for the category you name by itself.
Just one more thing: most of the time, it's most useful to filter for every
contact which has that category, even if it's not the primary category.
That's why I gave you
set theContacts to every contact where its category contains {category
"Work"}
last time. But if you really want to check only for Primary category. you'd
do it this way:
set theContacts to every contact where its category starts with category
"Work"
Lists are ordered, so they start with a particular item. In the case of
contact (or other Entourage element) categories, the primary category is
always the one that 'starts' the category list. And 'starts with' does not
error on empty lists ({}).
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <
http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <
http://macscripter.net/scriptbuilders/>
Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.
PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.