How do I insert entries into OSX AddressBook?
I'd like to use Python to insert a record into my local OSX AddressBook. There's a lot of information already out there about using the appscript module (need to learn AppleScript), and the AddressBook module (need to learn ObjC API). There's a lot of information, that is, on how to extract information. I haven't seen a clean code example for creating a new record and inserting that into AddressBook. The closest was someone's absync script, but I am unable to getattr(ab_person, "First") so I'm not sure if that script as written is compatible with 10.6.8's included modules.
Posted Sep 16, 2011, 9:26 PM UTC
This might help you get started using the appscript module.
Any additional contact properties can be found by looking at the "person" entry in the Address Book's dictionary in the AppleScript editor (under the file menu). The only difference is that you should put underscores in the place of spaces and prefix property keys with k. Edit: Add example to add a phone number to a person.
Thanks, those newperson examples are exactly what I've been searching for! May I ask how you get from all the Class descriptions to newperson.phones.end.make() and how you determine the new= and with_properties=? While attempting to use the AddressBook module, I had searched through the Programming Guide (not knowing ObjC or any Apple programming in the past), and got stuck trying to create an ABPerson object. ABPerson seems to have an addPropertiesAndTypes method but I couldn't find an example for what to use in parameters. I might just jump ship and use appscript with your examples instead.
Note that the above uses Appscript and not PyObjc. I'd definitely suggest using Appscript instead. It's very simple and there's a program ASTranslate that will translate Applescript to Python + Appscript. To install just do sudo easy_install appscript at the command line. I do all my scripting with Appscript and have for years.