Title: Revised script: Insert Contact Email
Although after I posted my script for inserting a contact's E-mail address quickly, the ensuing discussion uncovered a number of ways that can be done without a script (see PS below), some of us still find the script most convenient when assigned a keyboard shortcut. Bryan Harris reported two problems with the script:
1. It would not, as promised, locate contacts by their nicknames.
2. If you type a partial name, first plus part of the last such as "Robert B", the script would return an error message about descriptor mismatch.
I've repaired these problems, and the revised script is included below. The <fastest> retrieval is still by typing the contact's entire name, first plus last. Next fastest is typing a partial name: first only, last only, or first plus the start of the last. A nickname search occurs only if these first two fail, so nickname retrieval is the slowest. For that, you might still want to try one of the non-script methods discussed in the P.S.
---- Start of script
---- Insert Contact Email \somI (Cmd-Shft-Opt-I)
---- Allen Watson, Sun, Nov 19, 2000 <[EMAIL PROTECTED]>
---- V1.1 - Fix bug in location by nickname or partial name
set aName to text returned of (display dialog "Enter full name, or company, last name, first name, or nickname of the contact" default answer "" buttons {"OK"} default button 1)
set theChoice to ""
tell application "Microsoft Entourage"
try
get contact aName
set theChoice to aName -- Use the name
end try
if theChoice is "" then -- Did not find by full name
set someC to {}
try
set someC to name of contacts whose name contains aName
end try
if (count someC) = 0 then
-- Try nickname field
try
set someC to name of contacts whose nickname contains aName
end try
end if
if (count someC) = 0 then
display dialog "Contact \"" & aName & "\" not found."
return
else if (count someC) = 1 then
try
get contact (item 1 of someC)
set theChoice to item 1 of someC
on error
set theChoice to ""
end try
else
set theChoice to choose from list someC with prompt "Which contact do you want to use?" without multiple selections allowed and empty selection allowed
if result is false then return
set theChoice to item 1 of theChoice
end if
end if
if theChoice is "" then return
set theC to contact theChoice
try
set mailAddress to "<" & default email address of theC & ">"
on error
display dialog theChoice & " has no default E-mail address!"
return
end try
set the selection to mailAddress
end tell
--- End of script ---
P.S. The non-script methods for inserting a contact's E-mail address:
1. In the CC field, begin to type the contact's name, and select the desired contact from the auto-completion menu that appears. Then, drag the result into your message, and finally, delete the address from the CC field. If you want only the mailing address without the person's name, you will need to delete the name from your message where it will appear when you drag the address.
2. Go to the Address Book.
A. Type the name, nickname or company name in the filter field, and you will (fairly quickly) locate the contact in the resulting filtered list.
B. For a faster lookup by last name only or nickname only, be sure the list is sorted by the field you want to search (click the column header if not), select any contact, and then type the first part of the name you are looking for. For instance, sort on the name field and then type "Smi" to find the first contact beginning with those letters.
Select the desired contact, type Cmd-C to copy, then switch back to your message and paste. Again, you will get both the name plus the E-mail address, and may wish to delete the name.
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984
My web page: <http://home.earthlink.net/~allenwatson/>
