[Pythonmac-SIG] AppleEvent examples
Michael J. Barber
mjb@uma.pt
Mon, 12 Aug 2002 14:56:40 +0100
On Saturday, August 10, 2002, at 11:30 PM, Jack Jansen wrote:
>
> On zaterdag, augustus 10, 2002, at 12:13 , Robin Siebler wrote:
>
>> I'm trying to learn how to automate some tasks in CodeWarrior using
>> MacPython. Well, really, I'm trying to puzzle out how to do them in
>> AppleScript and then pulling my hair out trying to figure out how to
>> convert what works in AppleScript into something that works in
>> MacPython (if only autocomplete worked on the Mac, that would help).
>> Are there any examples anywhere of using MacPython and AppleEvents?
>
> Unfortunately there are no good examples:-( The Demo/applescript.html
> is about the only documentation there is, and the example it uses won't
> work under OSX...
>
Nonetheless, I'd think that the example shown there is a pretty good one
to look at - it's very simple and shows the basics of how the
AppleScript verbs map onto the package structure.
However, the example that I found to be most useful was findertools.py.
The functions therein are all pretty short and easy to understand.
The approach is exactly what Bill Bedford described: "...it is usually
better to use python directly and only attempt the Apple events when you
really need to communicate with an application." This strategy matches
my own few uses of AppleEvents in MacPython, and makes me wonder if
everyone does it that way? Better stated, does anyone have an example
where they don't take this approach?
> If anyone could come up with some good examples that would really be
> very welcome. I think AppleScripting could be one of the areas where
> Python can really shine, but there's still quite a bit of a hurdle you
> have to jump over to get started.
>
Maybe we should consider using findertools as a case study in Pythonic
AppleScripting? It's a "real world" usage and we know that all MacPython
users will have it. I can have a go at writing a brief version, although
it may have to wait a week or so (Anyone who is impatient should feel
free to start without me!).