TITLE OF PAPER: Scripting the Mac with Python URL OF PRESENTATION: http://toys.jacobian.org/presentations/2005/appscript/ PRESENTED BY: Jacob Kaplan-Moss REPRESENTING: CONFERENCE: PyCon 2005 DATE: March 23, 2005 LOCATION: 307 -------------------------------------------------------------------------- REAL-TIME NOTES / ANNOTATIONS OF THE PAPER: {If you've contributed, add your name, e-mail & URL at the bottom} Apple Events vs Apple Script Apple Events is an eventing system Sending Apple Events from Python There will be an improved OSA component for Python Raw events (Carbon.AE) Use os.system('osascript -e ...') -- bad, but quick and fast gensuitemodule appscript - improves on gensuitemodule [Emails from Address Book example] from appscript import * ab = app('Address Book.app') people = ab.people.filter(its.emails != []) for person in people.get(): emails = ', '.join(person.emails.value.get()) print "%s: %s" % (person.name.get(), emails) There's a difference between objects and object specifiers in applescript. Running appscripts Must use pythonw - access to window manager Getting Help [Demo: Playing with the Finder] distinction between properties and elements Note: arrays in applescript start with 1 Translating AppleScript to appscript [Automating things in OmniGraffle example] keywords in applescript translate well into Python If apps don't have scripting built in, you can use GUI Scripting Important tips Dont' forget get(), set(), and use pythonw Use python whenever possible Do large OSA calls rather than lots of small ones Use filter Q: What were the difficulties that you encounter with 0 vs 1 based subscripting A: Either do the translation in the bridge, or in the mind of the programmer Targeting applescript users instead of python users -------------------------------------------------------------------------- REFERENCES: {as documents / sites are referenced add them below} -------------------------------------------------------------------------- QUOTES: -------------------------------------------------------------------------- CONTRIBUTORS: {add your name, e-mail address and URL below} Ted Leung Linden Wright -------------------------------------------------------------------------- E-MAIL BOUNCEBACK: {add your e-mail address separated by commas } -------------------------------------------------------------------------- NOTES ON / KEY TO THIS TEMPLATE: A headline (like a field in a database) will be CAPITALISED This differentiates from the text that follows A variable that you can change will be surrounded by _underscores_ Spaces in variables are also replaced with under_scores This allows people to select the whole variable with a simple double-click A tool-tip is lower case and surrounded by {curly brackets / parentheses} These supply helpful contextual information. -------------------------------------------------------------------------- Copyright shared between all the participants unless otherwise stated...