Python

Hamish Sanderson's Appscript brings AppleScript terminology to Python. It comes with a standard installer package; double-click and run the installer and you're good to go. Scripts must be run using pythonw, not plain python. Here's the code for generating our model events:

from appscript import *
bb = app('BBEdit')
bb.make(new=k.document)
bb.documents[1].text.set('Hello, world!')

No glue is necessary; like JavaScript OSA, Appscript reads the dictionary and constitutes an appropriate application object behind the scenes. It does this very quickly, and it's even faster if you run the supplied background application AppscriptTerminologyServer. The Python code is structured in a compact, intuitive, highly legible manner, incorporating all the best features of UserTalk and JavaScript; this is partly due to Python itself and partly due to Appscript's clean and thoughtful implementation. Appscript is also easy to learn. An included tool, htmldoc.py, generates an HTML-formatted display of an application's dictionary with the Python version of its terminology. (Alternatively, you can use the HTMLDictionary standalone application, included with the installer, which does the same thing.) And a particularly nice extra is an interactive help command for exploring either the terminology or the live attributes of an application's objects. So, for example, within the interactive pythonw interpreter:

>>> bb.documents[1].help('-s') ================================================================================ ...

Get AppleScript: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.