Local and Global Properties for Chunk Expressions
Chunk expressions provide a powerful way of handling text data in SenseTalk scripts. The local and global properties described here let you control how chunks are accessed. For additional information about using chunks in SenseTalk, see Chunk Expressions.
Setting or Changing Local and Global Property Values:
You can set a global property value with the SenseTalk commands Set
or Put
. Note that when you reference one of these properties, you must use the word the
before the property name to distinguish it from an ordinary variable.
Examples:
set the searchrectangle to [1,2,2,3]
put 2 into the remoteworkinterval
You can add or change specific named properties within a global property like this:
set the namedColors.pink to color("RGB,1.0,0.5,0.5") -- Adds pink to the namedColors global property and defines its RGB color value
set the listFormat's separator to " & " -- Sets the separator property of the listFormat global property
Properties can also be set or updated by using the setoption
or setoptions
commands. The setoption
command lets you update a single property, and setoptions
lets you update multiple properties.
Examples:
setoption searchrectangle, [1,2,2,3]
setoptions {searchrectangle: [1,2,2,3], scriptlogging: yes}
Because setoption
and setoptions
are specific for use with global and local properties, you omit the word the
from the property name in the command syntax for these commands.
For additional information about working with local and global properties, see Local and Global Properties in SenseTalk.
the wordDelimiter
Local Property, the defaultWordDelimiter
Global Property
,
Values: Any character or list of characters, which will serve as separators between words in a container
Default:
- For
the wordDelimiter
: The current value ofthe defaultWordDelimiter
global property - For
the defaultWordDelimiter
: Space, Tab, and Return
Behavior: These properties specify the set of characters recognized as separators between words in a container. Any sequence of these characters, in any order or combination, can appear between words.
the wordDelimiter
property is local to each handler. Setting its value in one handler doesn't affect its value in other handlers called from that handler, or vice versa. When each handler begins running, the wordDelimiter
in that handler is initially set to the value of the defaultWordDelimiter
global property.
Example:
set the wordDelimiter to "." // Changes the local word delimiter to period
Example:
put "A man, a plan, a canal. Panama!" into palindrome
put word 4 of palindrome //Returns 'plan,'
set the wordDelimiter to ".,!?;:" & space & tab
put word 4 of palindrome //Returns 'plan'
set the wordDelimiter to ",."
put word 4 of palindrome //Returns ' Panama!'
Example:
set the defaultWordDelimiter to " " // Changes the word delimiter to space across all handlers
Example:
set LookupNumber to "102,311,421.000.631.521"
set the DefaultWordDelimiter to comma&period
set Row to the fifth word of LookupNumber
log Row // Displays '631'
You can also specify a delimiter directly in a word chunk expression by including a delimited by
clause, as described in Custom Chunks.
Related:
the lineDelimiter
the itemDelimiter
the wordQuotes
Local Property, the defaultWordQuotes
Global Property
Values: A list of two values for the beginning and ending quote delimiters, or a single value that will be used as both the beginning and ending delimiters. You can also set it to empty
or None
to disable word quoting, or to Standard
to restore the default quoting.
Default:
- For
the wordQuotes
: The current value ofthe defaultWordQuotes
global property - For
the defaultWordQuotes
: Straight double quotation marks
Behavior: These properties specify the quote character or characters used to identify quoted "words" in a word chunk. By default, any word beginning with a double quote character will include all characters up to and including the next double quote character (including any enclosed characters from the wordDelimiter
local property).
the wordQuotes
property is local to each handler. Setting its value in one handler doesn't affect its value in other handlers called from that handler, or vice versa. When each handler begins running, the wordQuotes
in that handler is initially set to the value of the defaultWordQuotes
global property.
Example:
set the wordQuotes to "*"
Example:
set Introduction to "Welcome to *The Manor*"
log the third word of Introduction // Displays '*The
set the wordQuotes to "*"
log the third word of Introduction // Displays '*The Manor*'
Example:
set the wordQuotes to empty -- Disable quoting
put "Hi, I'm [[my long name]]" into format
set the wordQuotes to ("[[","]]")
put word 3 of format -- [[my long name]]
set sentence to <<Jack said "Let's go see a movie.">>
put word 3 of sentence -- "Let's go see a movie."
set the wordQuotes to empty -- Disable quoting
put word 3 of sentence -- "Let's
Example:
set the DefaultWordQuotes to none // Disables word quoting
Example:
set Introduction to <<Welcome to "The Manor">>
put word 3 of Introduction // Displays '"The Manor"'
set the DefaultWordQuotes to none
set Introduction to <<Welcome to "The Manor">>
put word 3 of Introduction // Displays '"The'
the lineDelimiter
Local Property, the defaultLineDelimiter
Global Property
Values: A list of strings that can separate line items when evaluating a line chunk expression. The order of the items in the list is important because they are matched in the order given. For example, to match the common line endings CR, LF, and CRLF, be sure to list CRLF before CR. Otherwise, if CRLF is encountered in text, it will match CR first and be treated as two line endings in a row. Setting the lineDelimiter
to empty
returns it to the list of standard line endings: CRLF, Return, CarriageReturn, LineSeparator, ParagraphSeparator.
Default:
- For
the lineDelimiter
: The current value ofthe defaultLineDelimiter
global property - For
the defaultLineDelimiter
: The list of standard line endings: CRLF, Return, CarriageReturn, LineSeparator, ParagraphSeparator
Behavior: These properties specify the list of delimiter strings recognized as separators between lines of text. You can change the line delimiter to a specific line ending type, such as the Return character (technically, this character is the line feed, LF). This setting works fine for most text that a script interacts with. Text files produced on different platforms (Mac, Windows, Linux) might use other line endings.
To make it easy to work with a variety of files, the lineDelimiter
is initially set to a list of standard line endings: CRLF, Return, CarriageReturn, LineSeparator, ParagraphSeparator. If you set the lineDelimiter
to a custom list, you can later set it to empty as a shortcut that automatically restores it to the standard list.
You might also want to change the lineDelimiter
to take advantage of the fact that it provides a list of delimiters, in order to access chunks of text that might be separated by several different characters.
the lineDelimiter
property is local to each handler. Setting its value in one handler doesn't affect its value in other handlers called from that handler, or vice versa. When each handler begins running, the lineDelimiter
in that handler is initially set to the value of the defaultLineDelimiter
global property.
Example:
set the LineDelimiter to ","
Example:
set stuff to "button" & tab & "paperclip" & tab & "pencil"
set the lineDelimiter to tab
log the second line of stuff // Displays 'paperclip'
Example:
set the lineDelimiter to empty -- Use all standard line endings
put "C:\songs/Solas/BlackAnnis" into songPath
set the lineDelimiter to ("/","\")
put line 2 of songPath -- "songs"
Example:
set the DefaultLineDelimiter to tab
Example:
set stuff to "button" & tab & "paperclip" & tab & "pencil"
set the DefaultLineDelimiter to tab
repeat with each line of stuff
put it
end repeat
The output for the above command would look something like the following:
button
paperclip
pencil
You can also specify a list of delimiters directly in a line chunk expression by including a delimited by
clause, as described in Custom Chunks.
Related:
the wordDelimter
the itemDelimiter
the itemDelimiter
Local Property, the defaultItemDelimiter
Global Property
Values: Typically, a single character
Default:
- For
the itemDelimiter
: The current value ofthe defaultItemDelimiter
global property - For
the defaultItemDelimiter
: , (comma)
Behavior: These properties specify the character recognized as the separator between text items in a container. Most often, a single character is used as a delimiter, but it can be set to a longer sequence of characters if desired.
the itemDelimiter
property is local to each handler. Setting its value in one handler doesn't affect its value in other handlers called from that handler, or vice versa. When each handler begins running, the itemDelimiter
in that handler is initially set to the value of the defaultItemDelimiter
global property.
Example:
set the itemDelimiter to "*"
Example:
put "A man, a plan, a canal. Panama!" into palindrome
set the itemDelimiter to "."
put item 2 of palindrome //Displays" Panama!"
Example:
// The following function takes a full file path as input and returns just the directory of the file. It does this by parsing the path into items using "/" as the item delimiter.
function pathOfFile filename
set the itemDelimiter to "/"
delete the last item of filename
return filename
end pathOfFile
Example:
set the DefaultItemDelimiter to "/"
Example:
set the DefaultItemDelimiter to period
log item 2 of "apple.pie" // Displays 'pie'