Re: Efficient searching of Address Book
Re: Efficient searching of Address Book
- Subject: Re: Efficient searching of Address Book
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 11 Feb 2004 17:16:33 -0800
On 2/11/04 3:47 PM, "Lachlan Deck" <email@hidden> wrote:
>
I'm trying to figure out how I might make the following method far more
>
efficient than it is. It averages about 8 seconds to look up the name
>
of a person who has, as one of their emails, the given email address
>
anEmail. Here's the method...
>
>
on getNameFromEmail(anEmail)
>
tell application "Address Book"
>
repeat with eachPerson in every person
>
set theName to name of eachPerson
>
repeat with eachMail in (properties of email in eachPerson) as list
>
if (eachMail contains {value:anEmail}) then
>
return theName
>
end if
>
end repeat
>
end repeat
>
end tell
>
return null
>
end getNameFromEmail
>
>
I've tried fiddling with statements such as the following - but they
>
get a runtime error.
>
set thePersons to every person whose email contact info contains
>
{value:anEmail}
>
>
Any ideas?
on getNameFromEmail(anEmail)
tell application "Address Book"
set theNames to name of every person where value of every email of
it contains anEmail
end tell
return theNames
end getNameFromEmail
-- (P.S, Strictly speaking, it ought to be 'contains {anEmail}', but that
gives the wrong answer of {}, whereas 'contains anEmail' gives the right
answer. If you don't want the list brackets around the name(s) then do this:
on getNameFromEmail(anEmail)
tell application "Address Book"
try
set theName to name of first person whose value of every email
contains anEmail
on error
set theName to null
end try
end tell
return theName
end getNameFromEmail
--
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.