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

Kevin Walzer kw at codebykevin.com
Mon Jan 4 04:42:46 CET 2010


Hi all:

I'm trying to use aemreceive to allow one of my Python applications to 
receive simple Apple Events. Here's the relevant code that installs the 
event handler:

from aemreceive import *

def doScript(script):
     exec script

installeventhandler(
         doScript,
         'miscdosc',
         ('----', 'text', kae.typeUnicodeText)
         )


The idea here is to allow the application to execute Python code in 
response to an Apple Event.

I have included a simple SDEF file in the app bundle that adds the 
appropriate command:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Python Terminology">
	<suite name="Python Suite">
		<command name="do script" code="miscdosc" description="Execute a 
Python  script.">
			<direct-parameter description="Script to execute">
				<type type="text"/>
				<type type="text"/>
			</direct-parameter>
			<result description="Result" type="text"/>
		</command>
	</suite>
</dictionary>

And, finally, in the info.plist file, I mark the application as scriptable.

However, when I try to open the application's AS dictionary in Script 
Editor, the application is grayed out, showing that it is not 
scriptable. Furthermore, when I run this script in Script Editor:

tell app "MyApp"
	do script "print \"foo\""
end tell

I get this error:

"Expected end of line, etc. but found “script”."

Do I need to do anything else here, i.e. add anything else to 
info.plist? Or log out/log back into to re-register the application with 
the system?

I'm using Python 2.6.2 and Tk 8.5 on Leopard, with four-way builds of 
both. The application is wrapped up with bundlebuilder because of my 
continuing difficulties with py2app.

Any advice is appreciated...

Thanks,
Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


More information about the Pythonmac-SIG mailing list