[Pythonmac-SIG] appscript and XXXX - what is my app instance returning?

has hengist.podd at virgin.net
Wed Mar 30 16:06:45 CEST 2005

'me' wrote:

>I am having much fun with appscript and QuarkXpress6.x [...] 
>Unfortunately, when you do get lost like I am. You're completely 

While appscript saves you from the vagaries of the AppleScript 
language, it can't do anything about bugs and quirks in individual 
applications' scripting interfaces.

>Would someone please share their method for
>figuring out what my app instance is returning,
>and how I can coerce that into a form I can utilize?
>Quark = appscript.app('QuarkXpress')
>pw = Quark.documents[1].page_width   #This is what I want

Remember that while appscript uses an OO-like syntax for convenience 
it's not OO. It's a simple relational query builder plus RPC wrapper. 
Ditto AppleScript, except it has an even thicker layer of syntactic 
and semantic sugar on top. The downside of this is that it causes 
quite a bit of confusion amongst users who assume that because it 
looks like OO it will behave like it too.

(I've considered changing the syntax to avoid this problem, but 
that'd impact badly on its ease of use. I'd rather keep the syntax 
but make sure users know it's really just smoke and mirrors. Expect a 
bigger health warning in the docs for the next release.)

>  >>> type(pw)
><class 'appscript.specifier.Specifier'>

The line:

pw = Quark.documents[1].page_width

simply constructs a query (represented as an appscript Specifier 
object) identifying the page_width property of the first document 
element of the QXP application. To actually retrieve the value of 
that property from the application, you have to send the application 
an explicit 'get' command:

pw = Quark.documents[1].page_width.get()

>  >>> pw.get()
>     <_AE.AEDesc object at 0x1181c38>

This is a typical Quarkism: returning an opaque value that only it 
understands instead of using a standard AE type. AEDesc is the 
MacPython type used to hold raw Apple event data (in AS it'd appear 
as <<data ...>>), and is returned here as appscript doesn't have a 
suitable converter for it. If you're sending this value back to QXP, 
no problem. If you want to manipulate it in your script, you'll need 
to ask QXP to coerce it to a standard datatype (integer, float, 
string, etc.) before returning it, e.g.:


Not sure which coercions are supported here, so you may need to 
fiddle with it a bit. Good place to ask for QXP-specific advice would 
be [e.g.] the MacScrpt mailing list 



More information about the Pythonmac-SIG mailing list