Sets user-data item itemName of graphic obj to val, force evaluation of retval to trigger the error: Set retval to value of user data item itemName of obj Returns null if data item doesn't exist, or obj is invalid. Returns value of user-data item itemName of graphic obj. Note that the value set or retrieved is a string. Here are two useful methods for getting and setting user-data items of an object. That’s what I’ll be doing in the future.Using the name of the data item, you can set and retrieve its value in AppleScript. User data is useful when scripting as it's a way of storing values for future use after the script has completed its execution. If I had known this before I started drawing circles, I could have avoided the “select similar objects trick.” Instead, I’d have added the appropriate note to the first circle of each color, and the notes would have propagated every time I duplicated a circle. To see how many circles of each type are in the drawing, I look at the inspector pane in Script Debugger: This is the kind of script I was hoping to write yesterday. No need for counting variables, no need to loop through lists with repeat. applescript:Ģ: tell layer "Annotations" of canvas 1 of document 1ģ: set reds to every shape whose name is "Circle" and notes is "red"Ĥ: set greens to every shape whose name is "Circle" and notes is "green"ĥ: set blues to every shape whose name is "Circle" and notes is "blue" After doing the same for the green and blue circles, this short script did everything I wanted. So I selected all of my red circles (by clicking on one of them and using Edit‣Select‣Similar Objects) and entering “red” into the notes field, as above. You can type whatever you want into the notes field (the multi-line text area) and be able to access it in AppleScript through the notes property. If you go to the Info pane headed by the gear icon, you’ll see an Object Data section. OmniGraffle has a way of assigning data to objects that is completely under the control of the user and there’s no class warfare. Set reds to every shape whose name is "Circle" and fill color is redFillīut another approach did lead to an elegant solution. The lists generated by lines like applescript: Set greenFill to as RGB colorĭoesn’t produce an error, and he’s right. I could define them through coercion, applescript: If instead of defining the colors at the top of the script the way I did originally, applescript: This morning I wondered if I could get coercion to work the other way. If AppleScript used duck typing, it would recognize that a color walks like a list and talks like a list and wouldn’t need the coercion. To get the Boolean expression to ever return true. The OmniGraffle dictionary says the fill color property of a shape is of class color, not list, which is presumably why lines like applescript:ĭidn’t work (recall that variable c is an item in a list of fill colors) and I had to do a coercion, applescript: Next post Previous post AppleScript and the class struggleĪfter a Twitter conversation with ComplexPoint, I have a more elegant solution to the circle counting script I wrote about yesterday.īoth of the problems I had in writing the script are related to AppleScript’s approach to classes and variable typing.
0 Comments
Leave a Reply. |