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

Jack Jansen Jack.Jansen at cwi.nl
Tue Dec 2 07:24:35 EST 2003


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.

Does anyone know what goes on here? For some reason I cannot run the 
script (I get "OmniGraffle got an error: 
NSCannotCreateScriptCommandError"), but it does seem that I can change 
the script to
tell front document of application "OmniGraffle"
	set props to {origin:{100, 100}, size:{20, 20}, draws shadow:false, 
name:"Circle"}
	set shp to make new shape at end of graphics with properties props
end tell
and at least it still gets past the "set props", so I'm inclined to 
think that there's a global namespace for properties?

Either way, it seems that "with properties" is magic. Could we use this 
in our wrappers? I'm thinking of  something along the lines of making 
it possible to say
 >>> shape = ap.make(new=og.shape, origin=(100,100), size=(20,20), 
name="Circle")

This would be implemented by having make() collect all the unknown 
keyword arguments, look them up in the properties dict, stuffing them 
in a dict and passing that as the with_properties argument.

Or is this too much magic?
--
Jack Jansen        <Jack.Jansen at cwi.nl>        http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 4547 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20031202/b54dc319/attachment-0001.bin


More information about the Pythonmac-SIG mailing list