Hi, Adam.
All text elements in TextEdit have color, font, and size properties.
tell application "TextEdit"
{color, font, size} of paragraph -5 of text of front document
end tell
But only the first format in any paragraph, say, appears to be returned. So if your post above is copy/pasted to TextEdit, the color, font, and size of the line with the red are returned as {65535, 0, 0}, “Verdana-Bold”, and 11.0, even though it also contains dark grey, Geneva text.
A more accurate element is the ‘attribute run’. This is a block of equal formatting, delimited by any change of color, font, and/or size value. It’s more accurate from the point of view of saying: “This text has a certain color, font, and size,” but equating it to a particular paragraph can be fiddly. Of course, you can get the attribute runs of the paragraph itself:
tell application "TextEdit"
{it, color, font, size} of attribute runs of paragraph -5 of text of front document
end tell
--> {{"July 14, 2007 ", "-- about 16 point, but punBB doesn't understand [size=16]Stuff[/size] ", "
"}, {{65535, 0, 0}, {13107, 13107, 13107}, {0, 0, 0}}, {"Verdana-Bold", "Geneva", "Geneva"}, {11.0, 11.0, 11.0}}
A TextEdit ‘paragraph’ includes the line feed, if present, so the above result shows the red and grey text and the ‘black’ line feed!
I’m sure Kai came up with a GUI Scripting method for setting the selection in TextEdit, but I can’t find it at the moment. I’ll have another rummage around…
Later: No. His method is for finding out the selected range in a document. It’s apparently a read-only process:
tell application "System Events" to tell text area 1 of scroll area 1 of process "TextEdit" to if exists then -- Yuk! (NG)
set {x, y} to value of attribute "AXSelectedTextRange"
end if
The selection is from before character x to after character y in the text. Selection and insertion point are equivalent here. Selected text is a very wide “insertion point” and any text inserted will overwrite it. If there’s no selection, the value of x will be 1 more than the value of y, because the insertion point is between two adjacent characters and “before x” is the same point as “after y”. 