[Pythonmac-SIG] applescript to python examples for Address Book?

Bob Ippolito bob at redivi.com
Sat Aug 7 20:10:05 CEST 2004


This is PyObjC code..

import sys, codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
from AddressBook import *
ab = ABAddressBook.sharedAddressBook()
for person in ab.people():
	firstName = person.valueForProperty_(kABFirstNameProperty)
	lastName = person.valueForProperty_(kABLastNameProperty)
	emailProperty = person.valueForProperty_(kABEmailProperty)
	if emailProperty is not None:
		emails = [emailProperty.valueAtIndex_(i) for i in  
range(emailProperty.count())]
		print "%s %s (%s)" % (firstName, lastName, ', '.join(emails))

On Aug 7, 2004, at 1:46 PM, Kevin Altis wrote:

> This message should probably go to the PyObjC mailing list, but  
> perhaps someone will have the answer here. I want to be able to get a  
> list of names and email addresses from the Address Book using Python.  
> I have found the Address Book module for PyObjC, but the API doesn't  
> make much sense to me. Delving into the Apple Developer docs didn't  
> help much either.
>
> http://developer.apple.com/documentation/UserExperience/Reference/ 
> AddressBook/ObjC_classic/Classes/ABPerson.html#//apple_ref/occ/cl/ 
> ABPerson
>
> I'm hoping someone has a script example using PyObjC or aeve or  
> whatever else is available that is basically the equivalent of the  
> first part of the script from Panther Hacks.
>
> http://www.macdevcenter.com/pub/a/mac/excerpt/pantherhacks/
>
> -- open Address Book and loop through people
>
> tell application "Address Book"
>   repeat with thisPerson in the people
>     set thisName to name of thisPerson
>     repeat with thisAddress in email of thisPerson
>       set thisEmail to value of thisAddress
> ...
>
> Apologies if Python examples are lying around somewhere. I couldn't  
> find anything in my pythonmac-sig list archive, wiki, etc. I want to  
> grab the info and present it to the user as part of a wxPython app.
>
> ka
> ---
> Kevin Altis
> altis at semi-retired.com
> http://altis.pycs.net/
>
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig


More information about the Pythonmac-SIG mailing list