[Pythonmac-SIG] How does AppleScript find unqualified properties?
Bob Ippolito
bob at redivi.com
Tue Dec 2 08:40:04 EST 2003
On Dec 2, 2003, at 7:24 AM, Jack Jansen 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 are two namespaces, one for extensions and one for the current
application (as far as the tell block goes). So yeah, it's global.
> 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?
How is that any different from:
shape = app.make(new=og.shape, with_properties=dict(origin=(100, 100),
size=(20, 20), name="Circle")) ? 'with properties' isn't special, it's
just an optional "kwarg" of the make command.
-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20031202/6075a602/smime.bin
More information about the Pythonmac-SIG
mailing list