[Pythonmac-SIG] OSA Python (now with Cocoa)
bill fancher
bfancher@mac.com
Fri, 17 Aug 2001 19:01:34 -0700
I guess I should toss this into the mix, as it bears on a number of topics
recently discussed.
I've got an OSA component for Python that's reasonably functional. It's
resting at the moment, in anticipation of bug fixes in Mac OS X 10.1. It
uses the standard Python distribution compiled as a MachO shared library
(using Tony Lownds' dylib patch.)
It lets you to edit, run, and "debug" Python scripts in Apple's Script
Editor, or any other OSA compliant editor that might come down the pike.
It currently adds one built-in function, "App", which returns
built-on-the-fly application proxies for IAC. E.g., to have Finder rename
a folder:
App('Finder').Folder[14].Name = 'NewFolderName'
You can use StandardAdditions.osax (or any other scripting addition you
might run across):
r = App().Display_dialog('Hello, World', Buttons = ('B1', 'B2'))
App().Say( 'You chose ' + r.Button_returned )
This provides a bit of easy UI and access to a variety of Mac system
services on a fairly vanilla install (Unix distribution + Tony's patch +
OSA component).
Scripts can be saved from Script Editor as double-clickable applets or
droplets.
OSA Python can be used in most situations where AppleScript can be used.
For instance, you can run Python scripts from application script menus. An
unreleased version, running on Mac OS 9.x, allowed Python scripts to be
attached, e.g., to Hypercard objects and to send and receive Hypertalk
messages. Unfortunately, there are, at present, no applications I'm aware
of that support attached scripts under OS X. Presumably this will "just
work" when attachable apps become available. Maybe Folder Actions will
return soon.
Once Apple fixes StandardAdditions.osax, you'll be able to call
AppleScript, JavaScript or any other OSA compliant language from Python
and vice versa. Again, this was a working feature on 9.x.
Additionally, as I've recently discovered, the PyObjC module works with
OSA Python (though not without a few quirks). This means you can, in
theory at least, create double-clickable Python apps with arbitrary UI.
You can get a peek at the Mac OS 9.x version that was ALMOST released at
<http://home.pacbell.net/fancher/OSA_Python/OSA_Python_Notes.html>. Many
of the specifics mentioned there are "no longer operational", as the last
Bush administration used to say, and a number of features have been added,
most notably IAC. (BTW, the download link there is dead.)
So, it's still something of a toy, there are bugs that won't get fixed
right away, you need to get and apply Tony's patch and then build the
standard Python distribution, the docs are non-existent, script recording
doesn't work yet, and the source code is still not ready for prime time.
That being said, if anyone's interested in a binary copy of the component
and maybe some example scripts in exchange for feedback, please contact me
off-list.
--
bill
'Truth unfolds in time through a communal process.' - CQ