AppleScript and Python


A lot of my work on MorphGNT involves cleaning up and merging data from multiple sources. It's time consuming manual work and there's no instant gratification but it's worth it in the end.

I use a combination of Python scripts and manual editing in a text editor. Yesterday I thought I'd try AppleScript to automate some of the text editor work.

Unfortunately SubEthaEdit, which I've actually come to love as a standalone editor, even when not collaborating, doesn't seem to be scriptable. TextWrangler, however, is, so I downloaded that.

I've never written AppleScript before but fortunately, I was able to "record" myself performing the action and then bring up the resultant script and parameterize it.

So my script has lots of things like:

tell application "TextWrangler" to find bcv searching in text 1 of text document "ubs.txt"

The language is definitely optimized for doing little things (and the attempt to make it read like English is cute) and I'd hate to do anything too involved with it but I absolutely love the fact that I can automate applications (and even across applications) so easily.

What I really want now is the ability to kick off AppleScript from within Python and pass data from Python into a parameterized AppleScript.

Anyone done something like that before?

UPDATE (2005-03-30): There was a presentation at PyCon just a week ago on this sort of thing. See http://toys.jacobian.org/presentations/2005/appscript/. Looks very cool!

UPDATE (2005-04-03): Mark Nottingham pointed me to Scripting AppleScriptable Applications with Python.