[Pythonmac-SIG] Announce: OSATools

Michael J. Barber mjb@uma.pt
Sat, 30 Nov 2002 15:45:05 +0000


The recent discussion of AppleScript and OSA inspired me to finally 
write a package I've been thinking about for a while. I'm calling it 
OSATools, and it basically is a set of wrappers for the 'osascript' and 
'osacompile' OS X system calls. There are convenience functions for 
several cases, and a basic but useful class modeling an AppleScript 
interface.

You can do things like:

Python 2.2.1 (#1, 09/14/02, 00:14:43)
[GCC Apple devkit-based CPP 6.02] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from OSATools import AppModels
 >>> finder = AppModels.AppleScriptApp("Finder")
 >>> finder.tell('get the name of the startup disk')
'Macintosh HD\n'
 >>> finder.tellBlock(['set countList to {}',
...    'set the end of countList to the count of the folder "Library" of 
the startup disk',
...    'set the end of countList to the count of folder "Applications" 
of the startup disk',
...    'return the countList'])
'36, 88\n'
 >>>

Written quickly and only tested a bit, so there are probably bugs. Seems 
to work ok, though.

One caveat: OSATools uses pipes to talk to osascript and friends. In 
other words, it won't work with MacPython just yet, you need a Unix 
python.

Anyone who is interested can get it here:
<http://www.artsci.wustl.edu/~mjbarber/OSATools.tgz>

Hope this is useful for someone.

Michael