[Pythonmac-SIG] applescript to python examples for Address Book?
hengist.podd at virgin.net
Sun Aug 8 12:23:49 CEST 2004
Kevin Altis wrote:
>I want to be able to get a list of names and email addresses from
>the Address Book using Python.
>-- 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
Using appscript <http://freespace.virgin.net/hamish.sanderson/appscript.html>:
from appscript import *
for person in app('Address Book.app').people.get():
name = person.name.get()
for email in person.emails.value.get():
With well-written applications you can get this info with just a
couple of Apple events, which is much more efficient:
ab = app('Address Book.app')
print zip(ab.people.name.get(), ab.people.emails.value.get())
Note: don't let AppleScript/appscript's use of syntactic sugar fool
you. The Apple event object model uses a query-based interface more
powerful than conventional OO references, allowing a single message
to be sent to any number of objects.
More information about the Pythonmac-SIG