Re: [Pyobjc-dev] Python as an AppleScript Replacement?
Brought to you by:
ronaldoussoren
From: Peter M. <zig...@po...> - 2003-03-02 11:02:00
|
On Sunday, March 2, 2003, at 08:29 PM, Donovan Preston wrote: > On Saturday, March 1, 2003, at 11:46 PM, Peter Montagner wrote: >> I may be missing something, but I thought that MacPython's OSA >> support was limited to the AppleEvents level. AppleEvents are the low >> level interapplication messaging protocol. The code would still be >> useful of course, but it wasn't what I was thinking of (unless I'm >> missing something). You *could* look up the 4 char AppleEvent codes >> for the call you want manually and then send them and wait for a >> response, but this is nothing like osa.getApp("Finder").empty_trash. >> It is the core though. > > You are missing something -- gensuitemodule. I thought I must be. > gensuitemodule is a script that writes the python code which creates > and sends the low level apple events for you, based on the high level > AppleScript terminology. There are a few issues (resolvable) with > using it to it's fullest potential on OS X: > > 1) It currently asks you to select an application with a Carbon file > picker. The Carbon file picker exposed by python requires a > type/creator mask, and won't let you pick application bundles. > > 2) It currently opens the resource fork of the application you chose > and reads the binary data off disk, which it then parses to discover > the english names and corresponding four character codes. > > The solution to these problems is to instead send the 'ascr' 'gdte' > event directly to the application you wish to create a python module > for, by addressing the application's four character code. If you are > attempting to talk to a bundled application, the four character code > is usually in the plist file inside the bundle. > > I have some experimental code which allows you to use gensuitemodule > much more effectively on OS X by using the above apple event; however, > I still haven't found a way to discover an application's four > character code automatically. Unfortunately I am working on it in my > spare time, but I will attempt to get a patch enhancing gensuitemodule > for use on OS X into the sourceforge patch tracker sometime this week. Sounds like it does 90% of what I meant. IMHO, it would be more elegant to do it all on the fly with a call like osa.getApp("Finder"). After all, PyObjC doesn't generate a whole set of python modules to implement Cocoa, it does it all dynamically. I'm just throwing this out as a suggestion BTW. I probably won't have the time to actually implement it. I might take a bash at it though. Thanks for your help. Peter |