Problem with a list of properties

My Applescript commands OmniGraffle to create a year planner and populate the cells with data from my user calendar. I have just updated the script to add colour to certain entries.

The year planner displays text entries for each day in a single OmniGraffle rectangle, with multiple calendar entries being merged into a entry. The default text colour for an entry is black however each is searched and a different text colour is assigned depending on any keywords that are found.

OmniGraffle accepts multiple text strings in the form of a list of text records where each record contains a number of optional properties along with the text string that is to be displayed. My sub routine builds the contents of the this list and returns the following list elements:

{{font:"Gill Sans", size:9, color:{0, 47802, 0}, alignment:left, text:"Grn Bin"}, {font:"Gill Sans", size:9, color:{65535, 8995, 10794}, alignment:left, text:" KP Dentist 09:15"}, {font:"Gill Sans", size:9, color:{35723, 0, 35723}, alignment:left, text:" tribunal doncaster "}}

This list of elements is stored in a variable tText which gets inserted into another command that tells Omnigraffle to create a rectangle and set its text to the contents of tText:

make new shape at end of graphics of first canvas with properties {origin:{Col3LeftMargin, myVerticalCursor}, size:{myNotesColWidth, myNormalCellHt}, draws shadow:false, name:"Rectangle", user name:"MyEntry", fill color:tCellColour, text:tText, user data:{CellDate:userDataDate}}

The issue is that when tText is built in the subroutine and the result is passed to OmniGraffle via the main body of the script, OmniGraffle ignores the property “alignment:left” while correctly actioning all the other properties. If however a test list is created in the main body of the script, OmniGraffle uses the alignment property correctly.

The only difference that I can see in the creation of the property lists is that one created in the main script is inside a tell block while the other, in the subroutine, is not. Sure enough when I add a tell statement to wrap the code in the subroutine the alignment property is set and read correctly by OmniGraffle.

I am baffled as to what is going on and seek enlightenment.


Hi Simon.

alignment is very probably a label defined by OmniGraffle itself and published in its scripting dictionary.

When a script’s compiled, the AppleScript compiler checks to see if terms used inside a ‘tell’ block belong to the application being “told”. If so, it compiles the application’s tokens for those terms into the underlying script code, although the scripter will still see the terms themselves on the screen, perhaps in a different font. When the script’s run, it sends the tokens to the application, which will know what to do with them. Obviously there must be a copy of the application on the machine compiling the script.

A label compiled outside a ‘tell’ block (or in a ‘tell’ block to something that doesn’t recognise it) is interpreted as having been defined by the scripter, such as a variable or a property in a user-defined record. However, some labels are standard in AppleScript, which may be why OmniGraffle responded correctly to the other labels in your record.

Scripting additions and script libraries can also provide their own terms if the authors so choose, but the above explains what you were seeing.

Hi Nigel,

Thanks for your very clear explanation. I’ve never really thought much about the act of compiling but can see now that it is the time when the code is tokenised rather than at run time. I guess that I was lucky in that it was only one property that failed.

Thanks again,

best wishes