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

An AppleScript to publish Address Book as HTML Apps
I'm not sure what sort of tools DotMac may or may not have for this, but I've once or twice thought "gee, I wish I had a copy of my Mac address book online somewhere, so I could get to it from away from my Mac." Now that school is over for the year and I've had time to teach myself some more AppleScript, I wrote a little AppleScript to save my Address Book in HTML form. It doesn't do anything fancy, and isn't very easy on the eyes (a cost of having very readable code). If anyone out there wants to make the page prettier, I'd love to see (and use) the changes. Here's what you need to do to run the script:
  • Create a web root folder somewhere (I suggest an "Addresses" folder on your desktop, which you can then move to an online location.)
  • Open ScriptEditor, copy and paste the script into the window, and edit the first line to match the path to the directory you created above.
  • Click the Run button and wait. It takes about three minutes to run for me (335 address cards on a 1GHz G4), so it could take a while depending on the size of your Address Book database.
  • Open index.html in the folder you created, and use your web browser's "search" function to find an entry. Make sure to open index.html with a web browser and not a text editor, which might be the default.
Some things that still remain to be done:
  • Make the output much prettier.
  • Put the index page in alphabetical order.
[robg adds: I tested this script, and it worked as described.]
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[12,153 views]  

An AppleScript to publish Address Book as HTML | 10 comments | Create New Account
Click here to return to the 'An AppleScript to publish Address Book as HTML' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another software to do this...
Authored by: amit_kr on May 19, '05 01:30:42PM
HTMLize will convert all contacts, or certain groups, to HTML, or LDIF (to import into an LDAP server). Here's a screenshot: http://homepage.mac.com/amit.kumar/htmlize.jpg

VersionTracker link: http://www.versiontracker.com/dyn/moreinfo/macosx/17303

Consider this a shameless plug since I wrote it, but maybe someone will find it useful.

[ Reply to This | # ]

Another software to do this...
Authored by: chrismalanga on May 19, '05 02:22:51PM

The VersionTracker download took me to a .Mac 404 page. I was able to Google it and found Amit's site for download.

Here it is: http://tinyurl.com/bzlf7

Amit... you might want to check your VT link.

Chris

[ Reply to This | # ]

Another software to do this...
Authored by: amit_kr on May 19, '05 03:26:55PM

Thanks Chris, I'll update the link.

Amit



[ Reply to This | # ]
An AppleScriptt to publish Address Book as HTML
Authored by: alset on May 19, '05 02:19:56PM

Download link was broken. This one should work better:
http://homepage.mac.com/amit.kumar/.Public/htmlize-1.1.1.dmg

---
standing on the shoulders of giants



[ Reply to This | # ]
An AppleScriptt to publish Address Book as HTML
Authored by: osxpounder on May 19, '05 02:34:50PM

When I click the link, Safari displays your AppleScript on the screen. I tried copying and pasting it into Script Editor, but all the line breaks were wrong, and SE keeps hitting me with errors because it expected and "end of line".

I tried Option-clicking the link, but I keep getting a 0 bytes file. I don't understand. It's a text file, and it's obviously in the right place -- Safari won't download it.

I'd love to try this darn script, but right now I don't see another way than to go through it and manually replace all the line breaks. I tried using SE's Find & Replace to change each instance of "my" to "\n\nmy", but that didn't work. SE just shows me "\n\nmy" in my script instead of interpreting that as two new line commands preceding the word "my".

Next I tried TextWrangler, and found I could use "\r\rmy", for example. Nevertheless, SE still refused to compile, this time giving me an error I can't see a solution for. It says, "Expected "," or ")" but found end of line", but the code looks exactly the same as it does in other places, above that spot, that don't give the error. I tried deleting and retyping. No go.

What must I do to get this script into SE properly?

---
--
osxpounder



[ Reply to This | # ]
Try curling it
Authored by: jecwobble on May 19, '05 03:15:19PM

I had similar problems. I decided to use curl.

cd ~/Desktop
curl -o ab2html_scpt.txt http://www.macosxhints.com/dlfiles/ab2html_scpt.txt


[ Reply to This | # ]
An AppleScriptt to publish Address Book as HTML
Authored by: jbelkin on May 19, '05 03:34:24PM

Dot Mac does create an online version of your address book accessible by you when you log in - just run the sync and you're set.



[ Reply to This | # ]
An AppleScriptt to publish Address Book as HTML
Authored by: earthsaver on May 19, '05 05:21:49PM
AddressWeb is another application to consider for this conversion.

---
- Ben Rosenthal
Q16 1.25 - Tiger

[ Reply to This | # ]

An AppleScript to publish Address Book as HTML
Authored by: robophilosopher on May 19, '05 05:31:02PM
A couple have complained that the download is broken or something like that. You can download the latest version of the script (with a few improvements, like company name, etc) here (make sure to download, not view in your browser, as it's a .scpt file and not plain text). Or, try to copy-paste from below... Remember to change the first line!

property myOutputDirectory : "/Users/jomcmani/Documents/Addresses"

tell application "Address Book"
	set indexFile to my blankFile("index.html")
	my out("<html><head>", indexFile)
	my out("<title>Address Book</title>", indexFile)
	my out("</head><body>", indexFile)
	my out("<h1>Address Book</h1>", indexFile)
	my out("Click on a name below for address book information:<br><ul>", indexFile)
	
	repeat with x from 1 to the count of people
		set thePerson to person x
		set theName to the name of thePerson as string
		my out("<li><a href=\"" & x & ".html\">" & theName & "</a></li>", indexFile)
		
		set thisPage to my blankFile(x & ".html")
		my out("<html><head>", thisPage)
		my out("<title>" & theName & "</title>", thisPage)
		my out("</head><body>", thisPage)
		
		my out("<center><table cellpadding=3>", thisPage)
		my out("<tr><td colspan=2>", thisPage)
		
		if the image of thePerson exists then
			set thePicture to the image of thePerson as TIFF picture
			set tiffFile to my blankFile(x & ".tiff")
			set pngFile to my blankFile(x & ".png")
			write thePicture to tiffFile as TIFF picture
			
			my out("<img src=\"" & x & ".png\" align=\"left\" />", thisPage)
			
			do shell script ("sips -s format png \"" & POSIX path of tiffFile & "\" --out \"" & POSIX path of pngFile & "\"")
			do shell script ("rm -f \"" & POSIX path of tiffFile & "\"")
		end if
		
		my out("<font size=\"+3\">" & theName & "</font>", thisPage)
		
		if the job title of thePerson exists then
			my out("<br>" & the job title of thePerson, thisPage)
		end if
		
		if the department of thePerson exists then
			my out("<br>" & the department of thePerson, thisPage)
		end if
		
		if ((the organization of thePerson exists) and (the company of thePerson is false)) then
			my out("<br>" & the organization of thePerson, thisPage)
		end if
		
		my out("</td></tr>", thisPage)
		
		repeat with y from 1 to the count of phone in thePerson
			my out(("<tr><td><b>" & label of phone [y] of thePerson as string) & "</b></td>", thisPage)
			my out(("<td>" & value of phone [y] of thePerson as string) & "</td></tr>", thisPage)
		end repeat
		
		repeat with y from 1 to the count of email in thePerson
			my out(("<tr><td><b>" & label of email [y] of thePerson as string) & "</b></td>", thisPage)
			my out(("<td>" & value of email [y] of thePerson as string) & "</td></tr>", thisPage)
		end repeat
		
		repeat with y from 1 to the count of AIM Handle in thePerson
			my out("<tr><td><b>AIM</b></td>", thisPage)
			my out(("<td>" & value of AIM Handle [y] of thePerson as string) & "</td></tr>", thisPage)
		end repeat
		
		repeat with y from 1 to the count of Yahoo handle in thePerson
			my out("<tr><td><b>Yahoo</b></td>", thisPage)
			my out(("<td>" & value of Yahoo handle [y] of thePerson as string) & "</td></tr>", thisPage)
		end repeat
		
		repeat with y from 1 to the count of MSN handle in thePerson
			my out("<tr><td><b>MSN</b></td>", thisPage)
			my out(("<td>" & value of MSN handle [y] of thePerson as string) & "</td></tr>", thisPage)
		end repeat
		
		repeat with y from 1 to the count of ICQ handle in thePerson
			my out("<tr><td><b>ICQ</b></td>", thisPage)
			my out(("<td>" & value of ICQ handle [y] of thePerson as string) & "</td></tr>", thisPage)
		end repeat
		
		repeat with y from 1 to the count of Jabber handle in thePerson
			my out("<tr><td><b>Jabber</b></td>", thisPage)
			my out(("<td>" & value of Jabber handle [y] of thePerson as string) & "</td></tr>", thisPage)
		end repeat
		
		repeat with y from 1 to the count of address in thePerson
			my out(("<tr><td><b>" & label of address [y] of thePerson as string) & "</b></td><td>", thisPage)
			if (street of address [y] of thePerson is not missing value) then
				my multiLineOut((street of address [y] of thePerson as string), thisPage)
			end if
			if (city of address [y] of thePerson is not missing value) then
				my out((city of address [y] of thePerson as string) & ",", thisPage)
			end if
			if (state of address [y] of thePerson is not missing value) then
				my out((state of address [y] of thePerson as string) & " ", thisPage)
			end if
			if (zip of address [y] of thePerson is not missing value) then
				my out((zip of address [y] of thePerson as string), thisPage)
			end if
			my out("</td></tr>", thisPage)
		end repeat
		
		if (birth date of thePerson is not missing value) then
			my out("<tr><td><b>birthday</b></td>", thisPage)
			my out(("<td>" & month of (birth date of thePerson as date) as string), thisPage)
			my out((day of (birth date of thePerson as date) as string) & ", ", thisPage)
			my out((year of (birth date of thePerson as date) as string) & "</td></tr>", thisPage)
		end if
		
		repeat with y from 1 to the count of custom dates in thePerson
			my out(("<tr><td><b>" & label of custom date [y] in thePerson as string) & "</b></td>", thisPage)
			my out(("<td>" & month of (value of custom date [y] of thePerson as date) as string), thisPage)
			my out((day of (value of custom date [y] of thePerson as date) as string) & ", ", thisPage)
			my out((year of (value of custom date [y] of thePerson as date) as string) & "</td></tr>", thisPage)
		end repeat
		
		if (note of thePerson is not missing value) then
			my out("<tr><td><b>note</b></td>", thisPage)
			my multiLineOut(("<td>" & note of thePerson as string) & "</td></tr>", thisPage)
		end if
		
		my out("</table></center>", thisPage)
		my out("</body></html>", thisPage)
		
	end repeat
	
	my out("</ul></body></html>", indexFile)
	
end tell

on out(theText, theFile)
	write (theText as string) & return to theFile starting at eof
end out

on multiLineOut(theText, theFile)
	repeat with c from 1 to the number of paragraphs in theText
		my out((paragraph c of theText) & "<br>", theFile)
	end repeat
end multiLineOut

on blankFile(filename)
	set filePath to (myOutputDirectory & "/" & filename) as POSIX file
	open for access filePath with write permission
	set eof of filePath to 0
	close access filePath
	return filePath
end blankFile


[ Reply to This | # ]
An AppleScript to publish Address Book as HTML
Authored by: Lou Kash on May 20, '05 07:28:57AM
Thanks for the script.
A couple of comments:

  • The download link is still broken, it will download an "obscure" HTML file in Safari. You may want to zip the .scpt file before you post it to your web site.
  • I have also tried the other solutions suggested in the comments above. In fact, your script was the only one that really worked for me. The other solutions didn't output any useful results.
  • My Address Book has about 250 entries, many of them use either German umlauts or Central European (Czech) characters. If your script is used unmodified, the HTML files are wrongly encoded when viewed in a browser. Since the meta tag is missing, it's possible to change the encoding manually in web browser; in Safari I got the desired result by changing the encoding to "Central European (Mac OS)".
  • I have then modified your script to include the charset meta tag into each output file. For me the following tag works fine:
    <meta http-equiv="content-type" content="text/html; charset=x-mac-ce">

    The relevant parts of your script now look like this:
    tell application "Address Book"
    	set indexFile to my blankFile("index.html")
    	my out("<html><head>", indexFile)
    	my out("<title>Address Book</title>", indexFile)
    	my out("<meta http-equiv=\"content-type\" content=\"text/html; charset=x-mac-ce\">", indexFile)
    	my out("</head><body>", indexFile)
    	my out("<h1>Address Book</h1>", indexFile)
    	my out("Click on a name below for address book information:<br><ul>", indexFile)
    
    and
    		set thisPage to my blankFile(x & ".html")
    		my out("<html><head>", thisPage)
    		my out("<title>" & theName & "</title>", thisPage)
    		my out("<meta http-equiv=\"content-type\" content=\"text/html; charset=x-mac-ce\">", thisPage)
    		my out("</head><body>", thisPage)
    		my out("<center><table cellpadding=3>", thisPage)
    		my out("<tr><td colspan=2>", thisPage)
    
    Of course, depending on characters you might use in your address book, the charset may vary.

    The best solution for a browser view is, however, to encode all non-ASCII characters to HTML entities. This works well if I open an HTML output file in a text editor and use the UnicodeChecker's service "Unicode to HTML entities preserving ASCII".
    Unfortunatelly I'm not that skilled with AppleScript to figure out quickly how to automate that process using UnicodeChecker, but I can see in its AppleScript dictionary that it should be possible.

    [ Reply to This | # ]