-- html-dump-address-book.applescript - Guillaume Salagnac -- Time-stamp: "2008-04-22 10:20:53 salagnac" -- with lots of code shamelessly stolen from "HTMLize address book", -- by Amit Kumar http://homepage.mac.com/amit.kumar/ -- comments and bugfixes to guillaume.salagnac at gmail.com -- Dumps the contents of the Address Book in one big html page -- (intended for printing). -- -- Uses css for formatting (see and edit html-dump-address-book.css) -- usage: open in Script Editor and click "run" -- choose the filename for the generated file -- edit the html and/or the css and/or the script :-) property filename : "" as Unicode text try set filename to (choose file name with prompt "Please specify a filename:") on error beep display dialog "Really needs a filename" buttons "Exit" return end try -- sort the list AND remove duplicate entries on sort(l) if length of l = 0 then return l if length of l = 1 then return l set x to item 1 of l set ll to rest of l set l1 to {} set l2 to {} repeat with i in ll if x < i then set l2 to l2 & i end if if x > i then set l1 to l1 & i end if end repeat if length of l1 > 1 then set l1 to sort(l1) if length of l2 > 1 then set l2 to sort(l2) return l1 & x & l2 end sort on write_to_file(this_data, target_file, append_data) try set the target_file to the target_file as text set the open_target_file to ¬ open for access file target_file with write permission if append_data is false then ¬ set eof of the open_target_file to 0 write this_data as «class utf8» to the open_target_file starting at eof close access the open_target_file return true on error try close access file target_file end try return false end try end write_to_file ---- App (* Create the file *) set header to "" & return & ¬ "" & return & ¬ " " & return & ¬ " " & return & ¬ "" & return & ¬ "" & return my write_to_file(header, filename, false) set ab_people to {} tell application "Address Book" set ab_people to last name of every person end tell global sorted_people_list_ref set sorted_people_list_ref to a reference to sort(a reference to ab_people) (* display dialog "sorted list: " & (sorted_people_list_ref as string) *) tell application "Address Book" repeat with lname in sorted_people_list_ref repeat with p in (every person whose last name is lname) set t to "

" set t to (t & return & ¬ "" & ¬ name of p as Unicode text) & ¬ "" as Unicode text repeat with info in phones of p set t to ((t as Unicode text) & ¬ "" & ¬ " " & label of info & "" & ¬ " " & value of info as Unicode text) & "" & ¬ "" end repeat repeat with info in emails of p set t to ((t as Unicode text) & return & ¬ "" & ¬ " " & label of info & return & "" & ¬ " " & ¬ value of info & "" as Unicode text) & ¬ "" end repeat if (exists birth date of p) then set info to (birth date of p) set t to (t as Unicode text) & return & ¬ "" & ¬ "anni " & ¬ "" & date string of info & "" & ¬ "" end if if (exists home page of p) then set info to (home page of p) set t to (t as Unicode text) & return & ¬ "" & ¬ "home page" & ¬ " " & info & "" & ¬ "" end if repeat with info in AIM Handle of p set t to (t as Unicode text) & return & ¬ "" & ¬ "" & label of info & " " & ¬ "" & value of info & " " & ¬ "" end repeat repeat with info in Yahoo handle of p set t to (t as Unicode text) & return & ¬ "" & ¬ "" & label of info & " " & ¬ "" & value of info & " " & ¬ "" end repeat repeat with info in ICQ handle of p set t to (t as Unicode text) & return & ¬ "" & ¬ "" & label of info & " " & ¬ "" & value of info & " " & ¬ "" end repeat repeat with info in MSN handle of p set t to (t as Unicode text) & return & ¬ "" & ¬ "" & label of info & " " & ¬ "" & value of info & " " & ¬ "" end repeat repeat with info in Jabber handle of p set t to (t as Unicode text) & return & ¬ "" & ¬ "" & label of info & " " & ¬ "" & value of info & " " & ¬ "" end repeat repeat with info in addresses of p set t to (t as Unicode text) & return & ¬ "" & ¬ "" & label of info & " " & ¬ "" & formatted address of info & " " & ¬ "" end repeat if (exists note of p) then set info to (note of p) set t to (t as Unicode text) & return & ¬ "" & ¬ "note" & ¬ " " & info & "" & ¬ "" end if set t to (t as Unicode text) & "

" as Unicode text my write_to_file(t, filename, true) end repeat end repeat end tell