This example sets
to be equal to the second word in the active document. The move end of
range command is used to move the ending position of
(a range object) forward one word.
After this script is run, the second and third words in the document are selected.
if (count of words in active document) 3 then
set myRange to word 2 of active document
set myRange to move end of range myRange by a word item count 1
Command: move range
Collapses the specified text range to its start position or end position and then moves the collapsed
object by the specified number of units. Use this command to return a new text range object.
move range text range Required. An expression that returns a text range object.
[by enumeration] Optional. The unit by which the collapsed text range is to be moved. Can be
one of the following: a character item, a word item, a sentence item, a paragraph item, a line
item, a story item, a screen, a section, a column, a row, a window, a cell, a character
formatting, a paragraph formatting, a item unit, or a table. The default value is a character
[count integer] Optional. The number of units by which the specified text range is to be moved.
If count is a positive number, the object is collapsed to its end position and moved forward in
the document by the specified number of units. If count is a negative number, the object is
collapsed to its start position and moved backward by the specified number of units. The
default value is 1. You can also control the collapse direction by using the collapse range
command before using the move range command.
If the text range is in the middle of a unit or isn't collapsed, moving it to the beginning or end
of the unit counts as moving it one full unit.
The start position and end position of a collapsed text range are equal.
Applying the move range command to a text range doesn't rearrange text in the document. Instead,
it redefines the range to refer to a new location in the document.
If you apply the move range command to any text range other than a text range object variable (for example,
move range text object of paragraph 3 of selection
), the command has no effect.
This example sets
to the first paragraph in the active document and then moves the range
forward three paragraphs. After this script is run, the insertion point is positioned at the beginning
of the fourth paragraph.
set range1 to text object of paragraph 1 of active document
collapse range range1 direction collapse start
set range1 to move range range1 by a paragraph item count 3