Hacking your OSX Address Book with C, Racket and LaTeX
matt.might.net
matt.might.net
I previously wrote something in Python to sync between LDAP and the OS X address book using appscript. It was fairly straightforward. Edited to add: https://github.com/jaysoffian/absync/blob/master/absync
http://hints.macworld.com/article.php?story=2004110421223917...
Or, use this and Word: http://www.techtalkpoint.com/articles/how-to-mail-merge-appl...
I'm all about the geek credentials, and this is awesome. However, it's fairly impractical, and a lot of dev's who use a mac don't know Cocoa.
why use the MacRoman character set? UTF8 is a much better default.
also, the code uses CFStringGetCStringPtr() as if it can't ever fail. from the docs: "This function either returns the requested pointer immediately, with no memory allocations and no copying, in constant time, or returns NULL. If the latter is the result, call an alternative function such as the CFStringGetCString() function to extract the characters"
Fortunately, little Bobby Tables isn't one of my relatives.
I'll update it to use UTF8 when I get a free moment.
i brought up the CFStringGetCStringPtr() issue because my experience is that it works okay if you're using nothing but plain ascii for inputs and outputs, but tends to fail when anything more esoteric is involved. it is not just a theoretical concern, it has happened to me in the wild, with paying customers involved. on the other hand, i think it's reasonable to assume that every mac in existence will be able to handle UTF8.
this episode is reminding me that far too many programmers assume ascii everywhere. be nice to foreigners, folks.
http://www.emacswiki.org/emacs/MacOSTweaks#toc3
http://slashusr.wordpress.com/2009/08/16/importing-contacts-...
and it's no more difficult for C to spit out strings with some parens in them than it is strings with commas.
Why not CSV? S-Expressions are tree-structured, and that makes it easier to handle things like whether or not someone has a spouse (or multiple spouses) or a partner, or whether they have a title.
To parse S-Expressions, you just use (read) in Racket (or any Scheme for that matter). CSV isn't hard to parse, but it's not a 6-character expression.
Why not JSON? JSON is tree-structured, so it accounts for the issues above. But, most languages that slurp JSON don't have pattern-matching facilities as powerful as Racket.
If you look at the patterns I wrote to chew up entries and spit out labels, you'll see what I'm talking about.
Finally, the outputted S-Expressions are very human-readable.
/article author
Plus, it's by our very own epi0Bauqu (http://news.ycombinator.com/user?id=epi0Bauqu)