I have two scripts I’d like to write that would both require Applescript to do oparations only on the currently selected contact - something I’ve not been able to figure out how to do! Any help with the rest of these two scripts would also be appreciated:
(1) The first script would simply copy all the contact information (with the exception of the notes) to a new e-mail addressed to the contact.
(2) The second script is more complex. Becuse a very different template for Chinese contacts than I do for other contacts and I’d like to applescript the address book to do the following:
(1) switch last and first names
(2) add field phonetic names
(3) add field nickname
(4) copy the first and last name to the first and last phonetic name fields
You can’t do it from a generic Applescript, but it turns out you can write an applescript “plugin” that will work as a contextual menu from within a specific contact. Using this hint I was able to write my own. My problem was that the address book “copy mailing label” command sucked. It chokes on missing data, and doesn’t format addresses properly either (no comma after the state and before the zip, etc.) Here is what I came up with:
using terms from application "Address Book"
on action property
return "address"
end action property
on action title for aPerson with anAddress
return "My Address Label"
end action title
on should enable action for aPerson with anAddress
return true
end should enable action
on perform action for aPerson with anAddress
--line one information
set the_prefix to title of aPerson as Unicode text
if the_prefix = "missing value" then
set my_prefix to ""
else
set my_prefix to the_prefix & " "
end if
set the_firstname to first name of aPerson as Unicode text
if the_firstname = "missing value" then
set my_firstname to ""
else
set my_firstname to the_firstname & " "
end if
set the_lastname to last name of aPerson as Unicode text
if the_lastname = "missing value" then
set my_lastname to ""
else
set my_lastname to the_lastname
end if
-- line one carriage return check
if the_prefix = "missing value" and the_firstname = "missing value" and the_lastname = "missing value" then
set eol_one to ""
else
set eol_one to return
end if
-- line two information
set the_title to job title of aPerson as Unicode text
if the_title = "missing value" then
set my_title to ""
else
set my_title to the_title
end if
set the_department to department of aPerson as Unicode text
if the_department = "missing value" then
set my_department to ""
else if the_title = "missing value" then
set my_department to the_department
else
set my_department to ", " & the_department
end if
-- line two carriage return check
if the_title = "missing value" and the_department = "missing value" then
set eol_two to ""
else
set eol_two to return
end if
-- line three information
set the_organization to organization of aPerson as Unicode text
if the_organization = "missing value" then
set my_organization to ""
else
set my_organization to the_organization
end if
-- line three carriage return check
if the_organization = "missing value" then
set eol_three to ""
else
set eol_three to return
end if
-- line foour information
set the_street to street of anAddress as Unicode text
if the_street = "missing value" then
set my_street to ""
else
set my_street to the_street
end if
-- line four carriage return check
if the_street = "missing value" then
set eol_four to ""
else
set eol_four to return
end if
-- line five information
set the_city to city of anAddress as Unicode text
if the_city = "missing value" then
set my_city to ""
else
set my_city to the_city
end if
set the_state to state of anAddress as Unicode text
if the_state = "missing value" then
set my_state to ""
else
set my_state to the_state
end if
set the_zip to zip of anAddress as Unicode text
if the_zip = "missing value" then
set my_zip to ""
else
set my_zip to the_zip
end if
-- line five carriage return check
if the_city = "missing value" and the_state = "missing value" and the_zip = "missing value" then
set eol_five to ""
else
set eol_five to return
end if
--line six information
set the_country to country of anAddress as Unicode text
if the_country = "missing value" then
set my_country to ""
else
set my_country to the_country
end if
-- line six carriage return check
-- this section also strips out the country line if it is "USA" or the equivalent.
if the_country = "missing value" then
set eol_six to ""
else if the_country = "USA" or the_country = "U.S.A." or the_country = "America" or the_country = "United States" or the_country = "The United States" then
set my_country to ""
set eol_six to ""
else
set eol_six to return
end if
-- copy to clipboard
set the clipboard to ¬
my_prefix & my_firstname & my_lastname & eol_one & ¬
my_title & my_department & eol_two & ¬
my_organization & eol_three & ¬
my_street & eol_four & ¬
my_city & ", " & my_state & " " & my_zip & eol_five & ¬
my_country & eol_six
return true
end perform action
end using terms from
If you can improve on it, please post back here!!!