On 10/17/05 7:44 PM, "Nigel Stanger" <[EMAIL PROTECTED]>
wrote:

> On 18/10/2005 3:08 PM, "Paul Berkowitz" <[EMAIL PROTECTED]> spake thus:
> 
>> set fooMsgs to every  message of folder "bar" where its category contains
>> {category "foo"}
> 
> Excellent, this is pretty much exactly what I want; in fact I should be able
> to collapse it right down to a single statement as you suggest. I had tried
> to do something like this to start with, but couldn't quite figure out the
> right magic incantation of whose/where/whatever.
> 
> This to me is one of the biggest failings of AppleScript as a language ---
> statements that sound quite reasonable and that you think should work don't
> because you don't fully understand some facet of AppleScript's internal
> workings (in this case the requirement to use "where its" and {}). Yes, the
> same thing happens in just about any programming language, but it's more
> jarring in AppleScript because it's so "English-like". I've spent many
> frustrating hours yelling at scripts to just "do what I say!" :)

It's not actually a failing of the AppleScript language. There are two
issues here : one with 'contains', the other with 'whose category' in
Entourage.

1) If you want to script, you have to learn the language. If you ever got
the idea that "English-like" means you can just sit down and write English
sentences however they come into your head - surely you've been disabused of
that notion by now? That phase usually lasts from 15 minutes to about a
week. ;-) At most. The AppleScript Language Guide is absolutely clear on
this issue. So are all the books on AppleScript. Just learn it.  The problem
is that most of us first stumble into 'contains' using simple lists of
strings, where

    set theList to {"a", "b", "cd", "egxxx"}
    if theList contains "b" then
        say "This is a GOOD list!"
    else
        say "Boo!"
    end if

The critical line should really be, according to the ASLG,

    if theList contains {"b"} then

but AppleScript kindly coerces the string ( "b" ) to a single-item list
{"b"}, so it just works. Same for lists of numbers. That's very nice of
AppleScript, especially since it sounds like English, but it means that you
never learn the real rules until you transgress them in an application
somewhere , and then you haven't the faintest idea what's going on. (If you
omit the {brackets} with Entourage objects you get an extremely cryptic
error "Can't make message id 12345 into a vector." I can explain that if
anyone's interested.) There are a very few applications whose developers
have implemented 'application object to single-item list' for 'contains'
operator, but very few. I think the Finder may do that. But not Entourage,
nor most apps.

2) The business with needing 'where its category' instead of 'whose
category' is solely because the AppleScript implementer of Entourage rather
dubiously created the same term 'category' both for a class (an element of
the application - category "Work, category "Personal" etc.) AND for the name
of the property of several objects (message, contact, event, etc.) where
it's a actually a list of category objects. It has to be list, since these
objects can have multiple categories. Perhaps (in fact, I'm pretty sure)
Apple's guidelines to developers then in effect didn't warn against doing
this. So he had a good excuse. But he did confess, when this issue first
cropped up, that he had made a mistake and should have given the property
another name, such as 'category list'. You'll note that when Entourage
2004first introduced 'project' class, that the relevant property for objects
is 'project list'. So no confusion there.

It wasn't really fair of me to say that "AppleScript gets confused when
there's both a class and a property of the same name". It doesn't really get
confused - it has rules that dictate that a class (application element)
takes precedence over an item's property of the same name. Don't forget that
the 'whose' clause is in a 'tell application' block. So it's the
application's category, not the message's, which wins. And since the
statement now makes little sense (there are no messages where the
application itself contains category "foo"), the result is {}. Using 'where
its' - normally an exact synonym for 'whose' makes clear that you're talking
about the message's category (list), not the application's. 'it' is a very
powerful word in AppleScript.

You seen to be involved enough that you really should learn AppleScript
properly. I can't praise highly enough Matt Neuburg's "AppleScript: The
Definitive Guide" (O'Reilly). It deals clearly with all issues of syntax,
and is much more readable (and up-to-date) than the ASLG.


> 
> Anyway, I'll try that out and see how it goes. Thanks!


-- 
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.


-- 
To unsubscribe:                     
<mailto:[EMAIL PROTECTED]>
archives:       
<http://www.mail-archive.com/entourage-talk%40lists.letterrip.com/>
old-archive:       
<http://www.mail-archive.com/entourage-talk%40lists.boingo.com/>

Reply via email to