Re: Efficiently using whose on Address Book users
Re: Efficiently using whose on Address Book users
- Subject: Re: Efficiently using whose on Address Book users
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 22 Feb 2004 18:23:04 -0800
On 2/22/04 5:38 PM, "Paul Berkowitz" <email@hidden> wrote:
>
On 2/22/04 5:16 PM, "Jeff Porten" <email@hidden> wrote:
>
>
> I'm writing a script that I want to act differently based on whether a
>
> user is in the Address Book. Works fine when I search for "records
>
> whose name is...". But as mentioned earlier this month, "records whose
>
> email is..." doesn't work because email returns a list rather than a
>
> string.
>
>
>
> I have this solved with a script that recurses through the entire
>
> address book, but as you might expect, response time is now measurable
>
> in 10s of seconds where it was previously instantaneous. There is
>
> clearly some interapplication communication that does this better -- a
>
> rule in Mail.app to set the color of a message from someone in my
>
> Address Book happens immediately.
>
>
>
> Is there a way of constructing a whose clause that comes up with this?
>
> Barring that, at least a faster way of figuring out if email X appears
>
> in the address book?
>
>
As we've been through before, you can actually do this easily if you give it
>
a specific email. But what you want was something where you could give it
>
just a fragment of an email address, right? If you don't, then this works
>
just fine:
>
>
tell application "Address Book"
>
try
>
set foundPerson to (first person where value of every email of it
>
contains "email@hidden")
>
on error
>
set foundPerson to missing value
>
end try
>
end tell
>
--> person id "6AFC3E46-0268-11D8-81B7-000A958F49D8:ABPerson" of application
>
"Address Book"
>
>
(That's me.) It's only where you want to go looking for "silcom.com" or
>
"berkowit" that you need a loop.
But this doesn't actually error or create 'missing value' when it should,
due to that peculiar "feature" (I have another word for it) in Address Book
that setting a variable to something impossible doesn't error. But when you
next try to use the variable, _then_ it errors.
So add a 'get foundPerson' line, which errors as desired:
tell application "Address Book"
try
set foundPerson to (first person where value of every email of it
contains "email@hidden")
get foundPerson
on error
set foundPerson to missing value
end try
end tell
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.