Using the Address Book framework

Here's a bare-bones example of how to load and use the Address Book framework.

? (require 'objc-support)
;;; Load the framework
? (objc:load-framework "AddressBook" :addressbook)
;;; Looks like it worked...
? ns:ab-address-book
#<AB-ADDRESS-BOOK <ABAddressBook: 0x1743c300> (#x1743C300)>

Load this code (after doing the OBJC:LOAD-FRAMEWORK mentioned above), and you'll be able to say (absearch "smith") to look for the Smiths in your Address Book. Note that the output from NSLog may go to the system console.

(in-package "CCL")

(defun absearch (surname)
  (let* ((ab (#/sharedAddressBook ns:ab-address-book))
         (search (#/searchElementForProperty:label:key:value:comparison:
                  (#/autorelease (%make-nsstring surname))
         (results (#/recordsMatchingSearchElement: ab search)))
    (#_NSLog #@"%@" :id results)))
Last modified 12 years ago Last modified on Oct 21, 2009, 1:03:13 AM