Language Guide
CHAPTER 4
Commands
96 Command Definitions
The counting in this example requires several steps, beginning with the
reference to the outermost container. The reference paragraphs 2 thru 3
specifies a list of two items, each of which is a paragraph:
{"This is paragraph two.", "This is paragraph three."}
On the basis of this list, the Scriptable Text Editor evaluates the reference
words of paragraphs 2 thru 3 as a list of two items, each of which is
a list of the words in one paragraph:
{{"This", "is", "paragraph", "two."}, ¬
"This, "is","paragraph", "three."}}
Finally, the Scriptable Text Editor counts the items in each list and returns a list
of two items, each of which specifies the number of words in one paragraph:
{4, 4}.
References to nested containers are always evaluated before counting takes
place, beginning with the outermost container. Here’s another example:
tell document "simple" of app "Scriptable Text Editor"
count characters of words of paragraphs 2 thru 3
end tell
--result: {{4, 2, 9, 3}, {4, 2, 9, 5}}
The previous example demonstrated that the reference words of
paragraphs 2 thru 3 specifies a list of two items, each of which is a
list of the words in one paragraph:
{{"This", "is", "paragraph", "two."}, ¬
{"This, "is","paragraph", "three."}}
The Scriptable Text Editor counts the items in each list and returns a list of two
items, each of which is a list of the number of characters in each of the words in
one paragraph:
{{4, 2, 9, 3}, {4, 2, 9, 5}}