Title: Re: Inserting Contacts from Entourage
On or near 11/22/00 8:11 PM, Paul Berkowitz at [EMAIL PROTECTED] observed:
> Use the Copy Contact Info script (free-standing applet) that is one of three
> scripts in the Office Add-Ins available at the MacTopia site.
Can that be used when Word only is open and not Entourage?
Just wondering, since I usually have Entourage open anyhow. And never mind: I answered my own question. It can't; it opens Entourage.
The script is an alternate way of selecting and copying the contact info to the clipboard, but it sure does not solve the problem of the crummy interface to contacts provided in Word. And if you open the address book from within Word and select a contact, the script you mention does not take note of that fact; it still prompts for a name. What we need is a similar script that will copy the info for the selected contact. I think it would be fairly easy to alter this script to see if a contact is selected, and if so, to use that rather than prompting for a name.
Here is a version of the script that will use the selected contact(s) if any, instead of prompting for a name to look up. It will still prompt if no contacts have been selected. HOWEVER, I just tried running this script after opening the Address Book in Word and selecting a contact; the script switches to Entourage and selects the copy of the Address Book open there, rather than the one in Word. As far as I know, there is no way in Word’s scripting environment to access contact information at all! So the following script will be of use primarily if you switch to Entourage, look up your contact in the Address Book there, get the information you want onto the clipboard by running the script (it would work better if run from the Script menu rather than as a standalone applet), and then switching back to Word to paste the information. A pretty clumsy interface.
(* Copy Contact Info
v1.1 -- Revised Sat, Nov 25, 2000
Allen Watson <[EMAIL PROTECTED]>
Added code to check to see if any contact(s) is/are selected in the Address Book. If so, use that information instead of prompting for a name to look up.
*)
-- © 2000 Microsoft Corporation
-- with contributions from Paul Berkowitz and Steve Sell
property pSearchString : ""
property pDefaultAddress : "Work"
property pNonDefaultAddress : "Home"
set contactNotFound to ""
set searchResults to {}
-- ask user for search string
repeat while searchResults = {}
tell application "Microsoft Entourage"
activate
if the displayed feature of the front window is not address book 1 then
open address book 1
end if
set contactSelected to the selection
end tell
if contactSelected is {} then
set theDialog to display dialog contactNotFound & "Open contact whose name contains:" default answer pSearchString
set theSearchString to text returned of theDialog
-- look for contact(s) that match the search string.
-- if the string is null, open the "Me" contact (nice but undiscoverable shortcut)
if theSearchString = "" then
tell application "Microsoft Entourage" to set searchResults to {me contact}
else
tell application "Microsoft Entourage" to set searchResults to every contact whose nickname is theSearchString
if searchResults = {} then
tell application "Microsoft Entourage" to set searchResults to every contact whose name contains theSearchString
if searchResults = {} then
tell application "Microsoft Entourage" to set searchResults to every contact whose nickname contains theSearchString
if searchResults = {} then
tell application "Microsoft Entourage" to set searchResults to every contact whose company contains theSearchString
end if
end if
end if
-- search string does not match any contacts in the address book. Show error message and prompt user again
if searchResults = {} then set contactNotFound to "I could not find that name in your address book. Please try again." & return & return
end if
else
set searchResults to contactSelected
end if
end repeat
-- if there's only one match, parse out the contact's name to use as the default value for next run, and then open it
if (count of searchResults) = 1 then
set theName to name of item 1 of searchResults
if theName = "" then set theName to theSearchString
my OpenSelectedContact(item 1 of searchResults, theName)
return
end if
-- more than one match; build a list of the contact names that match the user's search string
set contactNames to {}
repeat with theContact in searchResults
tell application "Microsoft Entourage"
set theName to name of theContact
set theTitle to title of theContact
if theTitle � "" and theName � "" then set theName to title of theContact & " " & theName
set theSuffix to suffix of theContact
if theSuffix � "" and theName � "" then set theName to suffix of theContact & " " & theName
set theNickname to nickname of theContact
if theNickname � "" then
if theName � "" then
set theName to theName & " \"" & theNickname & "\""
else
set theName to "\"" & theNickname & "\""
end if
end if
set theCompany to company of theContact
if theCompany � "" then
if theName � "" then
set theName to theName & " (" & theCompany & ")"
else
set theName to "(" & theCompany & ")"
end if
end if
if theName = "" then set theName to "<untitled contact>"
end tell
set contactNames to contactNames & theName
end repeat
-- show contact list to user in order to narrow down to one contact
set theResult to choose from list contactNames with prompt "Choose a contact:" default items {(item 1 of contactNames)} ¬
without multiple selections allowed and empty selection allowed
try
set r to item 1 of theResult
on error
-- this shouldn't happen since empty selection is not allowed
return
end try
-- reverse engineer the contact id from the returned name
-- WARNING: this could fail if there exists more than one contact in the user's address book
-- with the same values for all of the fields:first, last, nickname, company, title, and suffix
-- The scenario is highly unlikely though, plus I can't think of a better design now.
repeat with i from 1 to (count of contactNames)
if r is (item i of contactNames) then
set s to i
exit repeat
end if
end repeat
-- open the contact using the contact ID
my OpenSelectedContact(item s of searchResults, r)
-- set the default string for next time to the full name of the contact, and then open the contact
on OpenSelectedContact(contactReference, contactName)
if contactName contains "\"" then
set o to offset of "\"" in contactName
if o � 0 then
if o = 1 then
set temp to text 2 thru -1 of contactName
set o to offset of "\"" in temp
set pSearchString to text 1 thru (o - 1) of temp
else
set pSearchString to text 1 thru (o - 2) in contactName
end if
end if
else if contactName contains "(" then
set o to offset of "(" in contactName
if o � 0 then
if o = 1 then
set o to offset of ")" in contactName
set pSearchString to text 2 thru (o - 1) of contactName
else
set pSearchString to text 1 thru ((offset of "(" in contactName) - 2) in contactName
end if
end if
else
set pSearchString to contactName
end if
repeat
tell application "Microsoft Entourage"
if pDefaultAddress = "Home" then
set theAddress to home address of contactReference
else if pDefaultAddress = "Work" then
set theAddress to business address of contactReference
end if
set AddressText to ""
if pDefaultAddress = "Work" and (company of contactReference � "") then set AddressText to company of contactReference & return
if street address of theAddress � "" then set AddressText to (AddressText & (street address of theAddress) & return)
if street address 2 of theAddress � "" then set AddressText to (AddressText & (street address 2 of theAddress) & return)
set cityStateZip to ""
if city of theAddress � "" then set cityStateZip to city of theAddress
if state of theAddress � "" then
if cityStateZip � "" then
set cityStateZip to (cityStateZip & ", " & state of theAddress)
else
set cityStateZip to state of theAddress
end if
end if
if zip of theAddress � "" then
if cityStateZip � "" then
set cityStateZip to (cityStateZip & " " & (zip of theAddress) & return)
else
set cityStateZip to cityStateZip & return
end if
else
if cityStateZip � "" then set cityStateZip to cityStateZip & return
end if
set AddressText to AddressText & cityStateZip
if country of theAddress � "" then set AddressText to (AddressText & (country of theAddress) & return)
--set AddressText to (AddressText & return)
if pDefaultAddress = "Home" then
if home phone number of contactReference � "" then set AddressText to (AddressText & "Home: " & (home phone number of contactReference) & return)
if other home phone number of contactReference � "" then set AddressText to (AddressText & "Home 2: " & (other home phone number of contactReference) & return)
if home fax phone number of contactReference � "" then set AddressText to (AddressText & "Fax: " & (home fax phone number of contactReference) & return)
if mobile phone number of contactReference � "" then set AddressText to (AddressText & "Mobile: " & (mobile phone number of contactReference) & return)
else if pDefaultAddress = "Work" then
if business phone number of contactReference � "" then set AddressText to (AddressText & "Work: " & (business phone number of contactReference) & return)
if other business phone number of contactReference � "" then set AddressText to (AddressText & "Work 2: " & (other business phone number of contactReference) & return)
if business fax phone number of contactReference � "" then set AddressText to (AddressText & "Fax: " & (business fax phone number of contactReference) & return)
if mobile phone number of contactReference � "" then set AddressText to (AddressText & "Mobile: " & (mobile phone number of contactReference) & return)
end if
try
if contents of default email address of contactReference � "" then set AddressText to (AddressText & (contents of default email address of contactReference) & return)
end try
end tell
set theAnswer to pSearchString & return & AddressText
set theDialog to display dialog "Type Cmd-C to copy the text to the clipboard:" default answer theAnswer buttons {pNonDefaultAddress, "Open Contact", "OK"} default button "OK"
if button returned of theDialog is pNonDefaultAddress then
set temp to pNonDefaultAddress
set pNonDefaultAddress to pDefaultAddress
set pDefaultAddress to temp
else if button returned of theDialog is "Open Contact" then
tell application "Microsoft Entourage"
activate
open contactReference
end tell
exit repeat
else if button returned of theDialog is "OK" then
exit repeat
end if
end repeat
end OpenSelectedContact
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>
- Re: Inserting Contacts from Entourage Allen Watson
- Re: Inserting Contacts from Entourage George Clark
