[Pythonmac-SIG] Calling python application from AppScript

has hengist.podd at virgin.net
Tue Nov 15 11:21:33 CET 2005


David Person wrote:

>When I use this applescript, it works:
>
>	tell application a
>		set r to processEvent("system", "start")
>	end tell
>
>...but when I try from another python application I get an error:
>
>from appscript import *
>ap=app('pc-av')
>ap.processEvent('system','start')

Two things: 1. appscript only works for applications that have an aete/sdef terminology resource, and 2. it doesn't support the special 'ascrbsbr' event, which is not something used outside of AppleScript applets. You'd need to use aem instead:

from aem import *
Application(a).event('ascrpsbr', {'snam':'processevent', '----':['system', 'start']}).send()


Anyway, the usual approach would be to define a standard AE handler, e.g. 'PCAVProE', with named parameters, '----' (direct) and 'Par2'. That allows you to write:

Application(a).event('PCAVProE', {'----':'system', 'Par2':'start'}).send()

or:

	tell application a
		set r to «event PCAVProE» "system" given «class Par2»:"start"
	end tell

You can then add an aete/sdef resource to provide terminology for that command if you want.

HTH

has
-- 
http://freespace.virgin.net/hamish.sanderson/


More information about the Pythonmac-SIG mailing list