The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniOutliner > OmniOutliner 3 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
AppleScript and text syltes? Thread Tools Search this Thread Display Modes
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.

Last edited by MLModel; 2010-11-21 at 10:37 AM..
 
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:
Originally Posted by Scott M. Neal View Post
how does one get not just a string but an object representing the contents of the cell?
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
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 OO3 > Help > Send Feedback especially as the Applescript interface is presumably being re-written for OO4.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
applescript to put text to the left of a point? gshenaut OmniGraffle General 0 2013-03-02 08:31 PM
How to center text in applescript efuchs OmniGraffle General 4 2012-04-13 08:05 AM
Formatting text from AppleScript ptorngaard OmniFocus Extras 0 2010-03-12 02:27 AM
Applescript example: exporting to a text file RobTrew OmniFocus Extras 6 2007-09-11 08:27 PM
applescript: text snippets steve OmniOutliner 3 for Mac 2 2006-05-19 09:10 AM


All times are GMT -8. The time now is 08:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.