[Pythonmac-SIG] AppleEvent examples
Mark Day
mday@mac.com
Mon, 12 Aug 2002 16:06:44 -0700
On Monday, August 12, 2002, at 02:00 PM, Jack Jansen wrote:
> On maandag, augustus 12, 2002, at 09:55 , Mark Day wrote:
>> For really simple AppleScripting stuff, the OSAm module in
>> :Mac:Contrib: is very handy since you can take ordinary AppleScript
>> source and pass it to CompileAndExecute. For some uses, it may be
>> simpler to use Python to build up the AppleScript source on the fly
>> and then let AppleScript compile and execute the actual AppleEvents
>> rather than try to build up the AppleEvents inside Python.
>
> If this is true then we're doing something wrong. For static scripts,
> okay, but if it is easier to dynamically create Applescript code than
> it is to use Python's own OSA API then we have to rethink the way the
> API is structured.
>
> Do you have examples of it being easier to go via Applescript?
For background, I was sending an AppleEvent to one application to
create a file, having Python massage the data a bit, then sending an
AppleEvent to a second application to open the modified file.
I already knew AppleScript's syntax to get the events I wanted. The
only part that needed to be dynamic was a filename or two, and that was
trivial as long as I assumed that I could ignore quoting issues (which
was true for the few systems it was deployed on).
To be honest, I put very little effort into trying to understand how to
do it directly in the Python OSA API. I read
:Mac:Demo:applescript.html and took a quick peek at the Disk Copy demo.
Right after that, I found the OSAm module. It sounded like it would
take a bit of effort to get started using the Python OSA API, compared
to a simple string substitution in an existing AppleScript (via
OSAm.CompileAndExecute).
If it needed to be more robust with volume/folder/file names, or if I
had to do something more complex with the applications, I think I would
have made the extra effort to understand and use the Python OSA API
rather than spend a lot of time trying to build up scripts that
AppleScript would parse properly.
-Mark