Hacker News new | past | comments | ask | show | jobs | submit login
Hacking your OSX Address Book with C, Racket and LaTeX (might.net)
54 points by plinkplonk on Dec 22, 2010 | hide | past | favorite | 20 comments



A very easy way to get to the address book (and anything that supports Applescript/Apple events) from a higher level language is via http://appscript.sourceforge.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


Appscript is pretty cool! Is there anyway to produce a bundle and distribute to other machines without Appscript installed?


Export via Applescript into CSV, for those without Xcode installed.

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.


To be slightly pedantic, neither CoreFoundation or AddressBook are part of the Cocoa framework.


okay, i see some problems here ...

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"


Thanks for the tip.

Fortunately, little Bobby Tables isn't one of my relatives.

I'll update it to use UTF8 when I get a free moment.



If you're going for safety, you should check to make sure that the string can use the particular encoding, rather than assuming that it will work. CFStringIsEncodingAvailable() will do that for you :)


no. CFStringIsEncodingAvailable() tells you whether a particular encoding is available on THE CURRENT COMPUTER, not for the given string.

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.


Speaking of the Address Book and Lisp, here are two pages on how to access its contents from Emacs:

http://www.emacswiki.org/emacs/MacOSTweaks#toc3

http://slashusr.wordpress.com/2009/08/16/importing-contacts-...


Anyone care to explain why use S-Expression as opposed to plain CSV or json?


Good question.

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


Thank you. I am trying to learn Lisp(Emacs Lisp and Clojure) and was curious on your format choice. Great article btw.


racket (and scheme) can read sexprs from a port with the 'read' procedure, which then uses the interpreter's parsing engine. loading csv or json require modules.

and it's no more difficult for C to spit out strings with some parens in them than it is strings with commas.


Credibility, of course.


Because Racket, a lisp dialect, is doing the processing, and every expression in lisp is an s-expression.


Google Contacts -> Export -> Mail Merge


What is Mail Merge?


Check out Duck Duck Go; it pulls snippets from Wikipedia and other data sources right to the top of search results, which makes it easy to get the gist of what something is, without much digging: http://duckduckgo.com/?q=mail+merge

Plus, it's by our very own epi0Bauqu (http://news.ycombinator.com/user?id=epi0Bauqu)


Hm, somehow the first hits look like ads - perhaps a change of fonts would be helpful? In any case, none provides the quick answer I was looking for (I already guessed it is about mergin mails). But thanks!




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: