Key Elements of the Language

SenseTalk in a Nutshell

A One Hour Introduction for Experienced Programmers and Inquiring Minds.

SenseTalk is a powerful, high level, and easy-to-read language. It is designed to be similar to English, avoiding cryptic symbols and rigid syntax when possible, in order to be both easy to read and to write. This section briefly describes many aspects of the language.

The information presented here is intended to provide a quick overview of most of the key elements of SenseTalk. Experienced scripters and programmers may find this is enough to get them started using SenseTalk. Other users may want to skim over this section to get a quick sense of what’s ahead before moving on to the more detailed explanations in following sections.

You may also find this section to be a convenient place to turn later when all you need is a quick reminder of how things work. For each topic, references are given to the section where more complete information may be found.


A SenseTalk script is a series of command statements. When the script is run, each statement is executed in turn. Commands usually begin with a verb, and are each written on a separate line:

put 7 into days

multiply days by 4

put days -- 28

A script is often stored as a text file on your computer.

SenseTalk is not case-sensitive: commands can be written in uppercase, lowercase, or a mixture without changing the meaning:

Put 7 into DAYS

(See Script Structure and Control Flow)

Simple Values

In SenseTalk there are simple values:

5 -- number

sixty-four -- number expressed in words

"hello" -- text string (full international Unicode text allowed)

empty -- constant

0x7F -- hexadecimal number

<3FA64B> -- binary data

(see Values)

Tech Note

There are no special "escape codes" for including special characters in text strings in SenseTalk. What you see is what you get.

Text Blocks

Multi-line blocks of text may be enclosed in {{ and }}. This type of text block is particularly useful for dynamically setting the script of an object, or for defining a block of data:

set names to {{

Harry Potter

Hermione Granger

Ron Weasley


(see Values)

Tech Note

Text blocks can use labels, similar to "here is" blocks in some other languages. This also allows them to be nested.


Operators combine values into expressions. A full range of common (and some uncommon) operators is available. A put command with no destination displays the value of an expression:

put 3 + 2 * 7 -- 17

put five is less than two times three -- true

put "a" is in "Magnificent" -- true

put 7 is between 5 and 12 -- true

put "poems/autumn/InTheWoods" split by "/"

-- (poems,autumn,InTheWoods)

Parentheses can be used to group operations:

put ((3 + 2) * 7) is 35 -- true

(see Expressions)


Text strings can be joined (concatenated) using & or &&. The & operator joins strings directly; && joins them with an intervening space:

put "red" & "orange" -- "redorange"

put "Hello" && "World" -- "Hello World"

(see Expressions)

Value assignment

Values can be stored in containers. A variable is a simple container. Either the put into or set to command may be used to assign a value to a container:

put 12 into counter

set counter to 12

Variables are created automatically when used; they do not need to be declared first.

(see Containers)

The Put Command

The put command can also append values before or after the contents of a container:

put 123 into holder -- "123"

put "X" before holder -- "X123"

put "Y" after holder -- "X123Y"

(see Containers)

Typeless Language

SenseTalk is a typeless language. Variables can hold any type of value:

put 132 into bucket

-- bucket is holding a number

put "green cheese" into bucket

-- now bucket holds a text string

Values are converted automatically as needed:

put ("1" & "2") / 3 -- 4

(see Expressions)

Unquoted Strings

Any variable that has not yet had a value stored into it will evaluate to its name. In this way, they can be used as unquoted strings, which can be convenient.

put Bread && butter -- "Bread butter"

(see Containers)


Some words have predefined values other than their names. These are commonly called “constants” but SenseTalk tries to allow you maximum freedom to use any variable names you choose, so only a very few of these are truly constant; the others can be used as variables and have their values changed.

The actual constants include true, false, up, down, end, empty, and return:

put street1 & return & street2 & return & city into address

if line 2 of address is empty then delete line 2 of address

The predefined variables include numbers and special characters like quote and tab:

put 2*pi

-- 6.283185

add one to count

put "Edward" && quote & "Red" & quote && "Jones"

-- Edward "Red" Jones

put comma after word 2 of sentence

(see Values.)


Comments can add descriptive information. Comments are ignored by SenseTalk when your script is running. The symbols -- (two dashes in a row), (an em dash), or // (two slashes) mark the remainder of that line as a comment:

// this script adds two numbers and returns the sum

params a,b — this line declares names for the two parameters

return a+b // return the sum (that’s all there is to it!)

For longer (or shorter) comments you may enclose the comment in (* and *). This technique is sometimes used to temporarily turn off (or “comment out”) part of a script. These "block comments" can be nested:


put "the total so far is : " & total -- check the values

put "the average is : " & total / count (* a nested comment *)


(See Script Structure and Control Flow)

Chunk Expressions

A chunk expression can be used to specify part of a value:

put word 2 of "green cheese"

-- "cheese"

put item 3 of "one,two,three,four"

-- "three"

put lines 1 to 3 of bigText

-- the first 3 lines

put the first 3 lines of bigText

-- also the first 3 lines

put any character of "abcdefg"

-- one letter chosen at random

Negative numbers count back from the end of a value:

put item -3 of "one,two,three,four" -- "two"

put chars 2 to -2 of "abcdefg" -- "bcdef"

Chunks of containers are also containers (you can store into them):

put "green cheese" into bucket -- "green cheese"

put "blue" into word 1 of bucket -- "blue cheese"

put "ack" into chars 3 to 4 of word 1 of bucket

-- "black cheese"

(see Chunk Expressions)

Tech Note

SenseTalk's chunk expressions provide capabilities similar to substring functions or slices in other languages, but are much more expressive and powerful.


You can create a list of values by merely listing the values in parentheses separated by commas:


("John",67, "555-1234", cityName)

("bread", "milk", "tofu")

Lists may include any type of value, including other lists:

("Mary", 19, ("555-6545", "555-0684"), "Boston")

Lists can be stored in containers:

put (2,3,5,7,11,13) into earlyPrimes

(see Values)

List Items

Items in a list can be accessed by number. The first item is number 1:

put item 1 of ("red", "green", "blue") -- "red"

put the third item of ("c","d","e","f","g") -- "e"

List items in a container are also containers (they can be stored into):

put (12,17,32) into numbers -- (12,17,32)

put 99 into item 5 of numbers -- (12,17,32,,99)

add 4 to item 2 of numbers -- (12,21,32,,99)

(see Chunk Expressions)

Combining Lists

Lists can be joined using &&&:

put ("red", "green", "blue") into colors

-- ("red", "green", "blue")

put (12,17,32) into numbers -- (12,17,32)

put colors &&& numbers into combinedList

-- ("red","green","blue",12,17,32)

To create a list of nested lists instead of combining into a single list, just use parentheses to create a new list:

put (colors,numbers) into nestedList

-- (("red","green","blue"), (12,17,32))

(see Expressions)

Property Lists

A simple object or property list is a collection of named values (called properties). Each value in an object is identified by its property name:

(size:12, color:blue)

(name:"John", age:67, phone:"555-1234", city:"Denver")

Objects can be stored in containers:

put (size:8, color:pink) into description

(see Values, Lists, and Property Lists)

Tech Note

SenseTalk's property lists are similar to collections known as hash tables, associative arrays, dictionaries or records in other languages. However, a SenseTalk property list is an object that can have behaviors as well as data values when certain special properties are set.

Object Properties

Properties in an object can be accessed by name:

put property width of (shape:"oval", height:12, width:16) -- 16

New properties can be created simply by storing into them:

put "red" into property color of currentShape

(see Containers)

An object’s properties can be accessed in several different ways:

put (name:"Michael") into mike -- create an object

put a new object into property cat of mike

-- create a nested object

put "Fido" into the name of mike's cat

put mike's cat's name -- Fido

put -- Michael

In addition, an object can access its own properties (or those of an object it is helping) using “me” and “my”:

put the age of me

if my name begins with "s" then ...

(see Objects and Messages)

Properties are containers – their contents can be changed:

add one to my dog's age-- it’s her birthday!

((see Containers, Lists, and Property Lists)


Lists and objects can be nested in complex ways:

(size:12, colors:(blue,orange), vendor:(name:"Jackson Industries",phone:"555-4532"))

(see Lists and Property Lists)


A range is an expression that uses "to" or ".." to specify a range of values. A range can be stored in a variable:

put 13 to 19 into teenRange

put teenRange -- 13 to 19

A range can be explicitly converted to a list:

put teenRange as list -- (13,14,15,16,17,18,19)

Or a range can simply be treated like a list:

put item 4 of teenRange -- 16

delete item 1 of teenRange -- teenRange is now a list

(see Ranges)


A range, a list, or a custom iterator object can be used as an iterator to obtain a sequence of values one at a time:

put "Z" to "A" into reverseAlphabet

put reverseAlphabet.nextValue -- Z

put reverseAlphabet.nextValue -- Y

put reverseAlphabet.nextValue -- X

(see Iterators)

Each Expressions

An each expression can generate a list of values of interest:

set saying to "Beauty lies beyond the bounds of reason"

put each word of saying where each begins with "b"

-- (Beauty,beyond,bounds)

Operations can be applied to each value in an each expression

put the length of each word of saying

-- (6,4,6,3,6,2,6)

put uppercase of each word of saying where the length of each is 6


(see Each Expressions)

Repeat Blocks

Repeat blocks are used to repeat a sequence of command statements several times:

repeat 3 times

play "Glass"

wait one second

end repeat

Several types of repeat loops are available, including repeat while, repeat until, repeat with and repeat with each:

repeat with each item of (1,3,5,7,9)

put it & tab & it squared & tab & the square root of it

end repeat

(See Script Structure and Control Flow)

Tech Note

All loops in SenseTalk use repeat. There are different forms of repeat that correspond to most of the popular loop constructs available in other languages.


if / then / else constructs let scripts choose which commands to execute based on conditions:

if hoursWorked > 40 then calculateOvertime

if lastName comes before "Jones" then

put firstName && lastName & return after firstPageList


put firstName && lastName & return after secondPageList

end if

(See Script Structure and Control Flow)

Calling Another Script

A script can run another script by simply using the name of the other script as a command:

simplify -- run the simplify script

(See Script Structure and Control Flow)


Parameters can be passed to the other script by listing them after the command name:

simplify 1,2,3

(See Script Structure and Control Flow)

Run Command

If a script's name contains spaces or special characters, or it is located in another directory, the run command can be used to run it:

run "more complex" -- run the "more complex" script

Parameters can also be passed using run:

run "lib/registerStudent" "Chris Jones","44-2516"

(see Working with Messages)


A script may include handlers that define additional behaviors:

to handle earnWages hours, rate

add hours*rate to my grossWages

end earnWages

A script can call one of its handlers as a command:

earnWages 40, 12.75

A handler in another script can be called using the run command:

run ScoreKeeper's resetScores "east", "south"

(See Script Structure and Control Flow)

Try/Catch Blocks

A script can catch any exceptions that are thrown when errors occur during execution:

try -- begin trapping errors

riskyOperation -- do something that might raise an error

catch theException

-- put code here to recover from any errors

end try

(See Script Structure and Control Flow)


A script may also throw an exception. If an exception thrown by a script is not caught by a try block, script execution will be stopped.

throw "error name", "error description"

(See Script Structure and Control Flow)

Local and Global Properties

Local and global properties control various aspects of script operation. They can be treated as containers, and are accessed using the word "the" followed by the property name:

set the numberFormat to "0.00"

insert "Natural" after the timeInputFormat

(see Containers)

File Access

File contents can be accessed directly:

put file "/Users/mbg/travel.log" into travelData

Files can also be treated as containers, allowing data to be written to them or modified in place. If the file does not already exist, it will be created:

put updatedTravelData into file "/Users/mbg/travel.log"

add 1 to item 2 of line updateIndex of file "/Users/mbg/updates"

(see File and Folder Interaction)


The sort command provides expressive and flexible sorting of items in a list or of text chunks in a container:

sort callsReceivedList

sort the lines of file "donors" descending

sort the items of inventory in numeric order by the quantity of each

(see Text and Data Manipulation)


The list of features and brief descriptions provided above give only an introductory summary of the language. SenseTalk offers many other capabilities not mentioned here, plus additional options for these features. The remaining sections of this manual describe all of SenseTalk’s features in detail.


This topic was last updated on February 26, 2019, at 10:29:15 AM.

Eggplant icon | Documentation Home | User Forums | Support | Copyright © 2019 Eggplant