5 ms·
Hacking your OSX Address Book with C, Racket and LaTeX
- js2 16y agoA 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/ 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 https://github.com/jaysoffian/absync/blob/master/absync
- riobard 16y agoAppscript is pretty cool! Is there anyway to produce a bundle and distribute to other machines without Appscript installed?
- sudont 16y agoExport via Applescript into CSV, for those without Xcode installed. http://hints.macworld.com/article.php?story=20041104212239178 http://hints.macworld.com/article.php?story=2004110421223917... Or, use this and Word: http://www.techtalkpoint.com/articles/how-to-mail-merge-apple-address-book-with-microsoft-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.
- Zev 16y agoTo be slightly pedantic, neither CoreFoundation or AddressBook are part of the Cocoa framework.
- famoreira 16y agoAnyone care to explain why use S-Expression as opposed to plain CSV or json?
- apl 16y agoCredibility, of course.
- sigstoat 16y agoracket (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.
- euroclydon 16y agoBecause Racket, a lisp dialect, is doing the processing, and every expression in lisp is an s-expression.
- mattmight 16y agoGood 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
- famoreira 16y agoThank you. I am trying to learn Lisp(Emacs Lisp and Clojure) and was curious on your format choice. Great article btw.
- allenbrunson 16y agookay, 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"
- mattmight 16y agoThanks 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.
- jessriedel 16y agoContext: http://xkcd.com/327/ http://xkcd.com/327/
- Zev 16y agoIf 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 :)
- allenbrunson 16y agono. 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.
- julian37 16y agoSpeaking 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://www.emacswiki.org/emacs/MacOSTweaks#toc3 http://slashusr.wordpress.com/2009/08/16/importing-contacts-from-osx-addressbook-to-emacs-bbdb/ http://slashusr.wordpress.com/2009/08/16/importing-contacts-...
- drivebyacct2 16y agoGoogle Contacts -> Export -> Mail Merge
- Tichy 16y agoWhat is Mail Merge?
- callahad 16y agoCheck 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 http://duckduckgo.com/?q=mail+merge Plus, it's by our very own epi0Bauqu (http://news.ycombinator.com/user?id=epi0Bauqu http://news.ycombinator.com/user?id=epi0Bauqu)
- Tichy 16y agoHm, 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!