[Pythonmac-SIG] Announce: OSATools

Bill Bedford billb@mousa.demon.co.uk
Tue, 3 Dec 2002 22:44:08 +0000


At 3:45 pm +0000 30/11/02, Michael J. Barber wrote:

>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.
>

It seems to me that.....

folderList = ['/Applications', '/Library']
countList = []
for f in dirFolder:
	countList.append(len(os.listdir(f)))
return countList

Is not only much more succinct, but is much easier to read.


-- 

Bill Bedford

He said no more is no less than it is
if in the future we live in the past