Applescript: set multiple shape properties in 1 call?
Apologies for re-post, I could not edit the title of the earlier post.
I am using Applescript to set the properties of some Omnigraffle shapes. I am using Python/appscript, but would appreciate any pointers in plain Applescript as well (or anything else). When I get the properties of a shape, Omnigraffle returns a dictionary of all key-value pairs (color, text, stroke, locked, etc.). When I create a new shape I can similarly send in a bunch of properties as a dictionary e.g. (in Python/appscript): doc.make(new=k.label, at=line.labels.end, with_properties={k.text: 'foo', k.draws_stroke = True}) Is there a way to update a bunch of properties of an [I]existing[/I] shape with a single call, passing in a dict of properties? If so, any restrictions on which properties can be set this way? e.g. When I tried shape.properties.set({k.locked: True}) -- it worked. But when I tried: shape.properties.set({k.text: 'foo'}) -- it did nothing. Thanks |
You can assign a sub-dictionary of properties:
[CODE]tell application id "OGfl" set lstSeln to selection of front window set oShape to item 1 of lstSeln tell canvas of front window --tell oShape to set {thickness, draws shadow} to {"Adjusted", 3, false} set properties of oShape to {thickness:4, draws shadow:true} set text of oShape to "Sample" properties of oShape end tell end tell[/CODE] [I]text[/I] however, does seem to be a recalcitrant property, and there are generally some screen refresh issues with setting text formatting through applescript - there seems to be a lag between the model seen by applescript and the image seen by the user. A scripted zoom can sometimes show an updated image, but reverting to the old zoom will still show the pre-script image. [COLOR="White"]--[/COLOR] |
or, within the scope of the object, assign a list of values to a list of keys.
[CODE]tell application id "OGfl" set lstSeln to selection of front window set oShape to item 1 of lstSeln tell canvas of front window tell oShape to set {thickness, draws shadow} to {3, false} --set properties of oShape to {thickness:4, draws shadow:true} --set text of oShape to "Sample" --properties of oShape end tell end tell[/CODE] [COLOR="White"]--[/COLOR] |
Thanks, Rob!
Separately, is there actually a way to explicitly disable & re-enable screen refreshes through a script? |
[QUOTE=Sophie;117234]is there actually a way to explicitly disable & re-enable screen refreshes through a script?[/QUOTE]
All I can immediately think of is toggling the [I]visible[/I] property of the layer(s) which you are writing to. |
Ah, that will work, thanks!
|
All times are GMT -8. The time now is 10:22 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.