[Pythonmac-SIG] creating a dictionary for an applescript app?

has hengist.podd at virgin.net
Tue Jun 19 15:50:48 CEST 2007


On 19 Jun 2007, at 00:43, tom wible wrote:

> i'm trying to access a function in an applescript.app i've  
> written...in applescript it's:
>
>    tell application "playRec"
> 	initRecList(false)
> 	set recList to listRecDict() -- returns a list of records
>    end tell
>
> but i want to do it in py-appscript (so i can use cheetah) but  
> ASTranslate errors: Untranslated event 'ascrpsbr'

Appscript doesn't provide an API for calling user-defined  
subroutines. You need to drop into aem and use raw AE codes to do that.


> i've set NSAppleScriptEnabled in my app's info.plist, and created  
> an sdef as suggested in http://lists.apple.com/archives/applescript- 
> implementors/2004/Feb/msg00028.html
> but i've not found any docs showing how to link the sdef to my  
> applescript...

The simplest thing would probably be to call your applet's user- 
defined subroutines via aem:

#!/usr/local/bin/python

from aem import *

playRec = Application(findapp.byname('playRec'))

playRec.event('ascrpsbr', {'snam': 'initRecList', '----':  
[False]}).send()
recList = playRec.event('ascrpsbr', {'snam': 'listRecDict', '----':  
[]}).send()


If you really want to add a dictionary, assuming you've saved your  
applet as a bundle, use sdp to convert your sdef to a .r file, then  
use Rez to append it to your applet's applet.rsrc file:

sdp -fa playRec.sdef
Rez playRec.r -a -o applet.rsrc -useDF


You'll need to define your applet's handlers using the raw AE codes  
given in your dictionary, of course, e.g.

on «event PRecIntL» arg
    ...
end «event PRecILst»

<command name="init rec list" code="PRecIntL" description="">
	<direct-parameter type="boolean" description=""/>
</command>


HTH

has
-- 
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html



More information about the Pythonmac-SIG mailing list