[Pythonmac-SIG] Python app with aemreceive is not scriptable

has hengist.podd at virgin.net
Tue Jan 5 17:41:41 CET 2010


Kevin Walzer wrote:

> Now my app responds to Apple Events and doesn't complain about a corrupted dictionary. However, I'm having some additional difficulty. It appears that Apple Events are bypassing the bundled Python and are going straight to the Tk framework instead. Tk/Aqua has pretty good AppleScript support, and implements a "do script" command that will execute Tcl scripts. My application responds to this code:
> [...]
> This is very weird, and I have no clue how to untangle it. My app won't respond to Apple Events at all without a valid sdef file in the bundle's Resources directory.

You only need to install event handlers for an application to respond to Apple events. The sdef is only there to provide human-readable terminology; not having one just means that users have to resort to raw chevron syntax (in AppleScript) or the aem API (in appscript) in order to communicate with it. (Cocoa Scripting-based apps do use the sdef for implementation purposes as well, but as your app doesn't use Cocoa Scripting to provide its Apple event interface it's a non-issue for you.)


> However, if the sdef is present, the commands and Apple Events defined there are ignored and are instead handled by the Tcl/Tk interpreter and its sdef instead. To avoid this conflict, I've tried removing the Tk sdef file, and changing the Apple Event class/ID of my Python event to something else, but these have no effect.

If I understand you, Tk implements a 'do script' handler that executes arbitrary Tcl scripts (right...no potential security issues there, then) and you are installing your own 'do script' handler as well. 

If that's the case, make sure your handler gets installed _after_ Tk has auto-installed its version, otherwise Tk will simply replace yours with its own. I'm not familiar with Tk though, so can't tell you at what point you need to do this. 

Alternatively, give your handler a different name and Apple event code so that it doesn't conflict with Tk's handler in the first place.

HTH

has
-- 
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net



More information about the Pythonmac-SIG mailing list