Title: Re: Finding all messages with category in AppleScript
On 10/17/05 1:28 PM, "Nigel Stanger" <[EMAIL PROTECTED]> wrote:
> Hi there, is there a quick way in AppleScript to find all messages that have
> category "foo" set, or am I stuck with iterating through the category list
> for each message? That is, I'm currently doing something like this:
>
> tell application "Microsoft Entourage"
> repeat with m in (every message of folder "bar")
> set cat to category of m
> repeat with c in cat
> if (name of c is "foo") then -- do something
> end repeat
> end repeat
> end tell
>
> This isn't particularly efficient, but I can't see any other obvious way of
> achieving this. Any pointers welcome, thanks.
You do need one repeat loop, but not two. It should be quicker doing this:
tell application "Microsoft Entourage"
set barMsgs to every message of folder "bar"
repeat with i from 1 to (count barMsgs)
set barMsg to item i of my barMsgs
if category of m contains {category "foo"} then
-- do something
end if
end repeat
end tell
1. Since the category of a message is a list of category, just search that list. You absolutely need the {curly brackets} around the sub-item (the category you're looking for) due to the AppleScript rule that says that 'contains' (and its converse 'is in') requires the same class (here, a list) on both sides of the operator.
2. If this is a top-level script (not in a handler/subroutine) 'my' before a list when iterating items makes it much faster for long lists (more than 100 items or so. Message folder scan have thousands of items, so this can be hugely faster.) If it _is_ in a subroutine /my' will error unless you've declared the list (barMsgs) as a global, but you can use a "Serge" script object (ask).
3. You could avoid even the first repeat loop that this way. Should be faster:
tell application "Microsoft Entourage"
set fooMsgs to every message of folder "bar" where its category contains {category "foo"}
repeat with i from 1 to (count fooMsgs )
set fooMsg to item i of my barMsgs
-- do something
end repeat
end tell
This will be MUCH faster since the list will be MUCH shorter. And depending on what 'do something' is, you might even be able to avoid the repeat loop entirely. If it's a simple command (such as moving the messages to a folder0, you can just use the command to operate on the entire list at once (in Entourage 2004, not earlier). In fact, you might even be able to use the command on the basic 'every message of folder "bar" where its category contains {category "foo"}' even in Entourage X.
5. You absolutely need 'where its' not ;whose' since otherwise AppleScript gets confused since 'category' is both a class (application property) as well as a property of message: you need the 'its' to specify you mean the message's category.
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>
PLEASE always state which version of Microsoft Office you are using - **2004**, X or 2001. It's often impossible to answer your questions otherwise.
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>
PLEASE always state which version of Microsoft Office you are using - **2004**, X or 2001. It's often impossible to answer your questions otherwise.
- Re: Finding all messages with category in AppleScript Paul Berkowitz
- Re: Finding all messages with category in AppleScript Nigel Stanger
- Re: Finding all messages with category in AppleScr... Paul Berkowitz
