Skip to main content

Chunk Syntax

Single Chunks

chunk number of expression


In this and the following syntax descriptions, chunk is used to represent any of the chunk types: character (or its abbreviation, char), word, line, item, text item, or list item. Similarly, chunks represents the plural version of these terms. number is a factor which evaluates to a positive or negative number, and expression is the source or destination value which the chunk refers to. Wherever the word "of" is shown, you may use either “of” or “in”, whichever seems natural to you at the time.

Chunk expressions for all types of chunks can be expressed in several different ways. You can describe a single chunk element:

put item 17 of scores into quiz3
put word 4 of "Mary had a little lamb" --> "little"

Negative numbers can be used to count backwards from the end of the source, with -1 indicating the last chunk element, -2 for the next-to-last, and so forth:

put item -2 of "apple,banana,pear,orange" --> "pear"

Ordinal Chunks

{the} ordinal chunk of expression

Chunk elements can also be referred to by their ordinal number (first, second, ... , millionth, or 1st, 2nd, ... , 1000000th):

get the third item of [9,12,13,42]
put it --> 13

You can use the form ordinal-to-last to count back from the end of the value (instead of using a negative number):

get the third-to-last item of [9,12,13,42]
put it --> 12

Special Ordinals (Last, Middle, Any, ...)

In addition to numeric ordinals, there are a number of “special ordinals” that can be used:

  • Any selects an element at random from among all those of the indicated type.

  • Middle (or Mid) selects the element closest to the middle, based on the total number of chunk elements of that type.

  • Last (or its synonyms Final, End, or Ultimate) selects the last chunk element (this is the same as specifying -1).

  • Penultimate selects the second-to-last chunk element (equivalent to specifying -2 or second-to-last).

  • Antepenultimate selects the third-to-last chunk element (equivalent to specifying -3 or third-to-last).

  • Preantepenultimate selects the fourth-to-last chunk element (equivalent to specifying -4 or 4th-to-last).

  • Propreantepenultimate selects the fifth-to-last chunk element (equivalent to specifying -5 or fifth-to-last).


put any item of "cow,ant,moose,goat,donkey,elephant" // selects one at random and displays it


get the middle character of "serendipity"
put it --> "d"


put the penultimate word of "Peace is its own reward." --> "own"


put the last line of gettysburgAddress into finalParagraph

Chunk Ranges

chunks firstNumberOrOrdinal to lastNumberOrOrdinal of expression
chunks range of expression
{the} first number chunks of expression
{the} last number chunks of expression

A chunk expression can refer to a range of chunk elements. The chunk range will include the beginning and ending elements specified, along with everything in between.


put characters 3 to 5 of "dragon" --> "ago"


put words 1 to 2 of "Alas, poor Yorick!" --> "Alas, poor"


put items middle to last of [1,2,3,4,5,6,7] --> [4,5,6,7]


put the second to penultimate items of [1,2,3,4,5,6] --> [2,3,4,5]


put items -3 to -1 of [1,2,3,4,5,6] --> [4,5,6]

A range value can also be used to access a range of chunks.


put chars 4..6 of "incredible" --> "red"


set fruitRange to 7..10
put chars fruitRange of "now appearing" --> "pear"

For ranges at the beginning or end of a value, you can also specify the “first n” or “last n” chunk elements


put the last three items of [1,2,3,4,5,6] --> [4,5,6]


get the first 4 characters of "abracadabra"
put it --> "abra"

Multiple Chunks (Lists of Chunks)

chunks indexlist of expression

You can access several distinct chunks of a source value as a list, by specifying a list of the ordinal chunk numbers.


put items [1,3,5,7] of scores into oddResults


put words [4,1,2,-1] of "Mary had a little lamb" --> [little,Mary,had,lamb]

The result of accessing multiple chunks is always a list. Negative numbers and the special ordinals "middle", "any", "last", and "penultimate" can also be used.


get items [-2,"middle"] of "apple,banana,pear,orange,peach"
put it --> [orange,pear]