AppleScript and text styles?
Is there a way to get or set named styles on selected text in a cell? on the entire cell? I can apply a named style to a word, for instance, but I can't find any evidence in OmniOutliner Professional's AppleScript object model for this styling. Attribute runs have style attributes, but they always seem to be empty. Moreover, I can't figure out how to access attribute runs: whether I ask for the text of a cell, the texts of a cell, the attribute runs of a cell, the attribute runs of the first text of a cell, attribute run 2 of the attribute runs of the first text of the texts of a cell, and so on, all I end up with is a string.
|
I'm having similar issues to the above poster.
According to the OmniOutliner AppleScript Dictionary, a cell contains text(s) element(s), which are specified elsewhere in the docs to contain elements including attribute runs, characters, and paragraphs. However, whenever I ask a cell for its text, I get a string, not a text object, so asking that object for "attribute runs" (an element) or "color" (a property) results in an error (strings don't know about those things). In fact, the value returned from "text of aCell" seems to be exactly the same as the property "value" of that cell--both strings. Here is the code I've been playing with trying to get what I want to work (more verbose than I would like, but I can't yet find the magic combo): tell front document of application "OmniOutliner Professional" repeat with aRow in selected rows set rowTopic to topic of aRow set rowCells to cells of aRow set rowStyle to style of aRow set rowStyleName to name of named style of rowStyle display dialog ¬ ("Row " & quote & rowTopic & quote & return & ¬ "RowStyle: " & rowStyleName ¬ ) repeat with aCell in rowCells -- first column is notes, 2nd is the default content column set cellText to text of aCell set cellValue to value of aCell display dialog ¬ ("Cell[" & (topic of row of aCell) & ", " & (name of column of aCell) & ¬ "]: " & "Text: " & quote & cellText & quote & return ¬ & "Value: " & quote & cellValue & quote & return ¬ ) if (length of cellText > 0) then -- set cellContent to attribute run of text of aCell set cellContent to paragraphs of cellText -- set cellContent to paragraph of aCell if ((count of cellContent) > 0) then set cellStyle to style of first item of cellContent set cellStyleName to name of named style of cellStyle else set cellStyleName to "no content to get style from?" end if else set cellContent to "" set cellStyleName to "no text to get style from?" end if display dialog ¬ ("Cell[" & (topic of row of aCell) & ", " & (name of column of aCell) & ¬ "]: " & quote & cellContent & quote & return ¬ & "Style: " & cellStyleName ¬ ) end repeat end repeat end tell My goal is to get the named style of the style of the paragraph within a cell (I've tried asking for both paragraph and paragraphs, but since the object I'm asking is a string and not an actual "text" object I get an error in both cases). The OmniOutliner Suite for paragraph adds the "style" property, but since I can't get the paragraph from the cell in the first place I don't get far enough to ask for the style (let alone the named style of the style). The above code works great for obtaining the name of the named style of the row style, and other code I have works great finding the column style, but I just can't get the contents of a cell to be represented in a object that responds to "style". I don't think this issue is specific to styles or named styles, but more generically "how does one get not just a string but an object representing the contents of the cell"? Thank you, Scott |
[QUOTE=Scott M. Neal;117465]how does one get not just a string but an object representing the contents of the cell?[/QUOTE]
Get a reference to the attribute runs of the text object. Asking for the 'text' property of the object just returns a flat string. [CODE]tell application id "OOut" tell front document tell first selected row tell attribute runs of its topic set lstSize to size set lstStyle to its style set lstText to its text set lstFont to font end tell end tell end tell end tell set lstProps to {} repeat with i from 1 to length of lstText set end of lstProps to {item i of lstText, item i of lstStyle, item i of lstFont, item i of lstSize} end repeat lstProps[/CODE] There may, however, be a bug in the style property of OO3 text objects, it seems to return a reference to the application rather than to the style. Worth flagging to the Ninjas through [B]OO3 > Help > Send Feedback[/B] especially as the Applescript interface is presumably being re-written for OO4. |
All times are GMT -8. The time now is 06:28 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.