Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Export Address Book entries to HTML via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Export Address Book entries to HTML via AppleScript
Authored by: wallybear on May 02, '08 02:27:00AM
I noted that the script stops with an error with badly formatted addresses, so I made this change to your script in the address retrieval part:

repeat with i in addresses
  try
    set tmp_addr to formatted address of i
  on error
    set tmp_addr to i's street & return & i's zip & " " & i's city & " " & i's state & return & i's country
    replaceStrings of tmp_addr to " " instead of "missing value"
  end try
 my add_data_item("postal", label of i, postal_uri, tmp_addr)
end repeat
and added the following method at the end of the script:

to replaceStrings of t to r instead of s
	set d to text item delimiters
	set text item delimiters to s
	set t to t's text items
	set text item delimiters to r
	tell t to set t to item 1 & ({""} & rest)
	set text item delimiters to d
	t
end replaceStrings


[ Reply to This | # ]
Export Address Book entries to HTML via AppleScript
Authored by: jonn8n on May 02, '08 09:22:37AM
It's probably a good idea to wrap more sections in try blocks in case there is a problem with the data. In case of an error with the formatted postal address, I'd construct it manually (this follows the US's convention for formatting postal addresses, update to your country's format as desired):

repeat with i in addresses
	try
		set tmp_addr to formatted address of i
	on error
		set tmp_addr to {}
		set {_street, _city, _state, _zip, _country} to i's {street, city, state, zip, country}
		if _street is not in {"", missing value} then set end of tmp_addr to {_street, return}
		if _city is not in {"", missing value} then set end of tmp_addr to {_city, ", "}
		if _state is not in {"", missing value} then set end of tmp_addr to {_state, " "}
		if _zip is not in {"", missing value} then set end of tmp_addr to {_zip}
		if _country is not in {"", missing value} then set end of tmp_addr to {return, _country}
		set tmp_addr to tmp_addr as Unicode text
	end try
	my add_data_item("postal", label of i, postal_uri, tmp_addr)
end repeat
Jon

[ Reply to This | # ]