[Pythonmac-SIG] How does AppleScript find unqualified properties?

has hengist.podd at virgin.net
Tue Dec 2 16:45:09 EST 2003


Jack wrote:

>When I looked at Winston's original posting again I noticed 
>something I don't understand. Usually, when you refer to a property 
>AppleScript has enough context to know where that property should 
>come from, but in the case given here it seems it doesn't:
>
>>tell front document of application "OmniGraffle"
>>	set shp to make new shape at end of graphics with properties ¬
>>		{origin:{100, 100}, size:{20, 20}, draws 
>>shadow:false, name:"Circle"}
>>end tell
>
>I pondered this for a while, and I can see only two ways in which 
>this could work:
>1.  "make new shape" has magic that tells it that when it's parsing 
>"with properties" the names there come from a shape object.
>2. The properties are really a global namespace.

There's no magic to the 'make' command or its 'with properties' 
parameter. However, the AppleScript compiler _does_ use some "magic" 
when parsing source code: it looks for 'tell application "Foo"' 
blocks in the source code and temporarily adds the additional 
terminology to its table of known keywords while it parses the code 
within that block. This might be what's confusing you.

As regards a record like the one in the example above, the compiler 
doesn't care what the keys are as long as they're valid (i.e. a 
class/property/variable name), and the application doesn't.


>Does anyone know what goes on here? For some reason I cannot run the 
>script (I get "OmniGraffle got an error: 
>NSCannotCreateScriptCommandError"),

Works fine here. Dunno why you'd be getting that error. (e.g. You'll 
get an NSContainerSpecifierError if there's no documents present when 
you execute it, but that's what you'd expect.)


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



More information about the Pythonmac-SIG mailing list