Re: Is there a more efficient way to do this?
Re: Is there a more efficient way to do this?
- Subject: Re: Is there a more efficient way to do this?
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 10 Dec 2006 15:27:38 -0800
- Thread-topic: Is there a more efficient way to do this?
On 12/10/06 2:16 PM, "Robert Nicholson" <email@hidden> wrote:
> Trying to find overlapping contacts by email address
>
> repeat with thisPerson in every person in group "Pimps"
> set e to the first email of thisPerson
> repeat with anotherPerson in every person in group "Whitelist"
> set e2 to the first email of anotherPerson
> if (e is equal to e2) then
> log "found a match"
> end if
> end repeat
> end repeat
>
> Is there a more efficient way to look up a contact by email address?
Yes. (You seem to be scripting Address Book.app. Any reason why you didn't
say so?)
tell application "Address Book"
set p to name of first person where (value of every email of it)
contains "email@hidden"
end tell
Put in in a try/error block in case there's no one with that email address.
That's a very efficient way to look up a contact by email address. But
that's not what your first script is doing. Since you don't know the email
address you're looking for, you're not looking up the contact "by email
address" are you? To find "overlapping" group members of _any_ email
address, you naturally need a repeat loop. But there are two ways of making
it faster:
set whitelist to {}
set dupEmailList to {}
tell application "Address Book"
set allPeople to (every person in group "Pimps")
repeat with i from 1 to count allPeople
set p to item i of my allPeople -- 'my' makes it faster
set e to value of first email of p
if {e} is not in dupEmailList then
set allOtherEmails to value of first email of (every person in
group "Pimps" where it is not p)
if {e} is in allOtherEmails then
set end of dupEmailList to e
set end of whitelist to {name of p, name of (first person of
group "Pimps" where it is not p and value of its first email is e)}
end if
end if
end repeat
end tell
whitelist
If some of the contacts have more than one email address, it's trickier but
can still be done. It also needs a try/error block in case a contact has no
email address.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden