Re: The Need for Speed: Finding Entourage contacts by display name or nickname
Re: The Need for Speed: Finding Entourage contacts by display name or nickname
- Subject: Re: The Need for Speed: Finding Entourage contacts by display name or nickname
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 22 Jun 2001 09:46:40 -0700
On 6/22/01 8:11 AM, "Jolly Roger" <email@hidden> wrote:
>
Hi folks,
>
>
Me again with another silly Entourage question... =)
Except you're quicker to acknowledge the replies that don't help, than the
ones that do.. ;-) (I hope the last 'email address' reply worked OK in the
end?)
>
>
The following script searches through the Entourage contact list looking
for
>
a contact that has the display name or nickname specified. This is
>
dreadfully slow in comparison to the built-in Entourage "find" utility,
>
which only searches for email addresses.
>
>
Anyone have any suggestions on what I might do to speed this up?
Entourage implements 'whose' filters, like the Finder does, which are
extremely fast. (That's what 'satisfying a test' means in the Dictionary:
'implements 'whose clauses' for this element.) They are implemented for
every element of every class in Entourage - it's been very thorough - except
they forgot to implement it for 'category' of contact, which is a nuisance.
That will be fixed.
Also, you may not be aware that you can get 'name' of contact: it's not a
property of contact but rather that, as an element of the application, it
can be specified 'by name' (see 'application' , element 'contact' in the
Dictionary). So you don't need to do that 'first name & " " & last name'
business, which would actually require a lot more checking in case it had
been entered just as first name or last name, with the other blank, or as a
nickname.
set theContacts to every contact whose name is "Jolly Roger" or nickname
is "Jolly Roger"
and check for duplicates. That will do what your whole script below does, a
lot faster, with no repeat loop, plus check for nickname, all in one shot.
If you don't care about duplicates then
try
set theContact to the first contact whose name is "Jolly Roger" or
nickname is "Jolly Roger"
on error
set theContact to make new contact with properties {first
name:"Jolly", last name:"Roger"}
end try
will do the job, including the possibility that someone, somewhere, knows
your real name and put in "Jolly Roger" as a nickname.
HTH.
--
Paul Berkowitz
>
>
-- start script
>
my FindContactByDisplayName("JollyRoger")
>
>
on FindContactByDisplayName(displayName)
>
set startTime to (the ticks) -- Jon's Commands
>
>
set foundContact to {}
>
tell application "Microsoft Entourage"
>
repeat with c from 1 to the count of the contacts
>
if (displayName = (contact c's first name & " " & contact c's
>
last name)) or (displayName = contact c's nickname) then
>
set foundContact to contact c
>
exit repeat
>
end if
>
end repeat
>
end tell
>
>
-- uses Jon's Commands
>
log ("elapsed time: " & ((the ticks) - startTime & " ticks"))
>
>
return foundContact
>
end FindContactByDisplayName
>
-- end script