Language Guide

CHAPTER 3
Values
Value Class Denitions 67
NOTES
You can’t change the style or font information from a script, but you can use
styled text to preserve style and font information when copying text objects
from applications to scripts. For example, you can use a script like this to
obtain styled text, manipulate it, and copy it back into a Scriptable Text Editor
document:
tell application "Scriptable Text Editor"
copy (word 1 of front document) to myStyledTitle
set myModifiedTitle to myStyledTitle & ", alpha release"
copy myModifiedTitle to word 1 of front document
end tell
Because the Scriptable Text Editor returns styled text when it returns the data
for text objects, you don’t need to coerce the returned text to styled text. The
style and font of the first word are preserved both when the word is copied to
the variable myStyledTitle and when it is concatenated with the string
", alpha release". The modified title that is copied back to the document
consists of the original title with its original style and font, plus the unstyled
text, ", alpha release", which appears in the style and font of the character
immediately preceding it.
Styled text also contains information about the form in which the text is
written. If you copy non-Roman text to a variable in a script as styled text,
AppleScript preserves the original text information even though the
Script Editor may not be able to display it correctly. If you then copy the text
to an application that can handle the text in its original form, the text is
displayed correctly.
Text 3
You can use the class identifier Text as a synonym for the identifier String, for
example, in coercions:
"A string" as string = "A string" as text
--result: true