Title: Insert contact info
I know not many scripts are getting posted here these days, but I thought I'd give the list a chance to beta test to see if it's worth posting to ASC.
It's called "Insert Contact Info", and it's similar to "Insert Contact's email" by Allen. It asks for a name (or at least a few letters), then presents you with a list of names that match. Then you can choose what information about them you'd like to insert into the email you're typing.
Very handy if you just need to insert a quick phone number or address into an email.
I have a PB G3 500MHz with about 400 contacts, so it runs well on my machine, but who knows on a slower box. Feel free to email me with suggestions or comments.
- Bryan
****************************************************************************
-- Insert Contact Info v2
-- 23 January 2001
-- original implementation by Allen Watson, "Insert Contact email"
-- by Bryan Harris, [EMAIL PROTECTED]
-- Feel free to contact me if you have problems with the script
tell application "Microsoft Entourage"
-- get contact keyword from user, theTxt
set theResponse to (display dialog "This script inserts information about a contact (such as their email address) into a draft message." & return & return & ¬
"Please enter in the contact's name or nickname." default answer "type contact name or nickname here" buttons {"Cancel", "OK"} default button 2 with icon note)
if button returned of theResponse is "Cancel" then return
set theTxt to text returned of theResponse
-- get list of matching contacts, theCs
set theCs to (every contact whose nickname contains theTxt) & (every contact whose display name contains theTxt)
if (count of theCs) is 0 then set theCs to (every contact whose company contains theTxt)
set theCount to (count of theCs)
if theCount is 0 then
display dialog "Sorry, no contacts were found by that name." buttons {"Cancel"} default button 1 with icon stop
return
end if
-- build list of displayable names, theNames
if theCount > 1 then
set theNames to {}
repeat with i1 from 1 to theCount
set theNames to theNames & (i1 & ". " & display name of (item i1 of theCs) as string)
end repeat
-- choose 1 from list by number, theIndex
set theC2s to ((choose from list theNames with prompt ¬
"Select the contact you'd like to insert information from:" default items (item 1 of theNames as list) without multiple selections allowed and empty selection allowed) as list)
if theC2s is false then return
set theC to item 1 of theC2s
set theIndex to ((characters 1 through ((offset of "." in theC) - 1) of theC) as string) as integer
else
set theIndex to 1
end if
set theC to item theIndex of theCs
set theOpts to {"default email address", "ID", "category", "title", "company", "home phone number", "home address", "business phone number"}
set thePrompt to ("Select the type of information you'd like to insert about " & (display name of theC) & ":")
set madeIt to false
repeat until madeIt
set theFields to ((choose from list theOpts with prompt thePrompt default items (item 1 of theOpts) without multiple selections allowed and empty selection allowed) as list)
set theField to item 1 of theFields
if theField is false then return
-- Get info on contact, newTxt
if theField is item 2 of theOpts then
set newTxt to ID of theC as text
else if theField is item 3 of theOpts then
set newTxt to category of theC as text
else if theField is item 4 of theOpts then
set newTxt to title of theC as text
else if theField is item 5 of theOpts then
set newTxt to company of theC as text
else if theField is item 6 of theOpts then
set newTxt to home phone number of theC as text
else if theField is item 7 of theOpts then
set theA to home address of theC
set newTxt to (street address of theA) as text
set theA2 to (street address 2 of theA) as text
if theA2 is not "" then set newTxt to newTxt & ", " & theA2
set newTxt to (newTxt & ", " & (city of theA) & ", " & (state of theA) & " " & (zip of theA)) as text
else if theField is item 8 of theOpts then
set newTxt to business phone number of theC
else
set newTxt to address of theC as text
end if
if newTxt is "" then
set thePrompt to ("The \"" & theField & "\" field appears to be empty. Please select again.")
else
set madeIt to true
end if
end repeat
-- Insert contact info into email
try
set selection to newTxt
on error
if button returned of (display dialog "This is uneditable text. You can try selecting \"Edit Message\" from " & ¬
"the Message menu, then running the script again, or simply click \"Place in new window\" to put the encoded " & ¬
"text into a new draft window." buttons {"Place in new window", "Cancel"} default button 2 with icon stop) ¬
is "Place in new window" then
make new draft window with properties {content:newTxt}
end if
return
end try
end tell
