Miscellaneous Operators
( )
(Parentheses) Operator
Behavior: Use parentheses to control the order in which operations are performed within an expression. See Precedence of Operators to understand the order in which operations are performed when parentheses are not used. When in doubt, use parentheses to ensure operations are carried out in the desired order. Also see Uses of Parentheses for more details.
Syntax:
( expression )
Example:
put 2 * (height + width) into perimeter
AsList
Function
Behavior: The asList
function is called with an object (property list) as a parameter, it first checks whether the object has an asList
property. If so, its value is returned. If not, and the object has an asListExpression
property, the value of that property is evaluated as an expression (equivalent to calling the value()
function) to obtain the list value. If the object has neither of these properties, an asList
function message is sent exclusively to the object and its helpers, and its return value is used.
If the target is not an object (or does not have an asList
or asListExpression
property or an asList
function handler) and it is not already a list, the target's string value is evaluated as an expression (equivalent to calling the value()
function) to obtain the list value.
Syntax:
{the} asList of factor
asList( expr )
Example:
put file "scores" as a list into testScores
Related:
Is A
, Is Not A
, Isn't A
, Is All
, Is Not All
, Isn't All
Operators
Behavior: Checks whether a value is valid as a particular type, or analyzes the contents of a value. You can test whether a value is or is not a number
, integer
, even number
, odd number
, positive number
, negative number
, positive integer
, negative integer
, point
, rectangle
, date
, time
, or Boolean
. A variable can be tested to see whether it is a list
, a range
, an iterator
, a file
, a folder
, a tree
, or an object
. You can also test whether a character or all characters in a value are digits
, letters
, alphanumeric
, uppercase
, lowercase
, punctuation
, blank
(or whitespace
), blankOrReturn
(or whitespaceOrReturn
), or controlChars
. You can tell if a value is actually a reference to another container, by testing whether or not it is a reference
. In addition, the is a
operator can also be used to test for custom object types if the object defines an objectType
property (see the ObjectType
property in Special Properties).
Syntax:
valueToTest is {not} a typeIdentifier
valueToTest is {not} all typeIdentifier
Examples: The following expressions all yield "true":
put pi is a number
put pi is not an integer
put -12 is an even number
put 5683 is an odd number
put 98.6 is a positive number
put 0 isn't a positive number
put -13.2 is a negative number
put 144 is a positive integer
put -1 is a negative integer
put "123, 12.5" is a point
put "123, 12.5, 245, 25" is a rectangle
put (snow is greater than rain) is a boolean
put (a,b,c) is a list
put 14..94 is a range
put (a,b,c) is an iterator
put "July 4, 1776" is a date
put "/System/Library/Fonts/Courier.dfont" is a file
put "/System" is a folder
put (partnum:"4X56N32", qty:14) is an object
put 6 is a digit
put character 2 of "4X56N32" is a letter
put "J946Ux" is an alphanumeric
put "a" is a lowercase
put "ABCdef" isn't all uppercase
put "(),.;:!?[]{}%\’/" is all punctuation
put space is a blank
put space & tab & return is all blankOrReturn
put tab is a controlChar
put @foo is a reference
put radius:23, objectType:("Shape", "Circle") is a "Circle"
put <"[", character, "]"> is a pattern
An error is raised if typeIdentifier is not one of the following valid identifiers, or an expression that evaluates to one of the built-in identifiers listed below, unless valueToTest is an object or property list.
If the valueToTest is an object, the is a
operator evaluates to the value returned by sending an isObjectType
function message to the object, with typeIdentifier as a parameter. The default implementation of this function checks the objectType
property of the object contains the typeIdentifier. If a property list has an objectType
property, it may be a single value or a list of values. If typeIdentifier is equal to any item in the objectType
list, the is a
operator will evaluate to true, otherwise it will be false.
Identifier | True When the Value to Test Is |
---|---|
Boolean logical | "true" or "false", "yes" or "no", "on" or "off", or empty |
date time | a value other than a single number that can be converted to a date or time value |
even number | a whole number that is evenly divisible by 2 |
file | a file object or file name of an existing file, not a folder |
folder directory | a file object or file name of an existing folder, not a plain file |
integer int | a "whole" number without any fractional part |
iterator | an iterable value such as a list or range |
list | a list |
negative integer | a whole number that is less than zero |
negative number | a number that is less than zero |
number | a number |
object propertyList | an object or property list |
odd number | a whole number that is not evenly divisible by 2 |
pattern | a pattern definition using SenseTalk's pattern language |
point | a list of two numbers, or two numbers separated by commas |
positive integer | a whole number that is greater than zero |
positive number | a number that is greater than zero |
range | a range |
rectangle rect | a list of four numbers, a list of two points, or four numbers separated by commas |
reference | a reference to another container |
tree | a tree |
The following identifiers can be used to test the type of characters in a text value:
Identifier | True When Every Character of the Value to Test Is |
---|---|
alphanumeric | a letter or a digit |
blankOrReturn whitespaceOrReturn | a space or a tab or a return |
blank whitespace | a space or a tab |
controlChar controlChars | a hidden control character such as return, tab, formfeed, etc. |
digit digits | a digit: 0,1,2,3,4,5,6,7,8, or 9 |
letter letters | an upper- or lower-case letter |
punctuation | a punctuation character such as , . ! ? ; : |
lowercase | a lower-case letter |
uppercase | an upper-case letter |
There Is A
, There Is Not A
, There Isn't A
, There Is No
, Exists
, Does Not Exist
, Doesn't Exist
Operators
Behavior: Tests for the existence of a file, folder, variable, object, or object property. In the case of variables, this operator returns true if the variable has been assigned a value.
Syntax:
there is [a | an] thingThatMayExist
there is not [a | an] thingThatMayExist
there isn't [a | an] thingThatMayExist
there is no thingThatMayExist
thingThatMayExist exists
thingThatMayExist does not exist
thingThatMayExist doesn't existWhere thingThatMayExist is one of:
file fileName
folder folderName
object objectIdentifier
property propertyName of _someObject
variable localOrDeclaredVariableName
global globalVariableName
universal universalVariableName
Example:
if there is a folder "BankReport" then ...
Example:
if there is no file "secretpasswords" then ...
Example:
if there is not an object "printHelper" then ...
Example:
if there is a property cost of material then ...
Example:
if there is a variable controller then ...
Example:
if file "answers" doesn't exist then create file "answers"
Example:
if property sequence of part exists then add 1 to part's sequence
Is Within
, Is Not Within
, Isn't Within
Operators
Behavior: Tests whether a point lies within a rectangle, whether one rectangle is completely contained by another, or whether a value falls within a given range. All forms of the is within
operator test for containment inclusive
of the edges or endpoints of the containing rectangle or range. So, for example 9 is within 5..9
will evaluate as true.
Points are always specified as a pair of numbers representing the x and y coordinates of the point. Usually, these two values are given as a two-item list such as [12,42], but a text string containing two numbers separated by commas can also be used, such as “12,42”.
Rectangles are specified as 4 numbers, representing the locations of the left, top, right, and bottom of the rectangle, such as [5,18,105,118] — this rectangle would actually be a square, with both width and height of 100. You can also think of the four numbers as describing two points, which are opposite corners of the rectangle. A rectangle can also be specified as a list of 2 points, such as [ [5,18], [105,118] ].
Syntax:
point is {not} within rectangle
rectangle1 is {not} within rectangle2
value is {not} within range
Example:
if mousePoint is within windowBorder then ...
Example:
if lastLoc + [12,8] is within [10,10,90,50] then ...
Example:
if windowRect is not within screenRect then ...
Example:
if day is within 1 .. lastValidDay then ...
&&&
List Concatenation Operator
Behavior: Joins two lists or values into a single list of values. The result of this operation is always a list, even if one of the operands is empty.
Syntax:
operand1 &&& operand2
Example:
put [1,2,3] &&& [4,5] into oneList -- results in [1,2,3,4,5]
Example:
put oneList &&& 6 --> [1,2,3,4,5,6]
Example:
put 0 &&& oneList --> [0,1,2,3,4,5]
Example:
put 12 &&& 42 into luckyList -- results in [12,42]
Joined By
, Split By
Operators
Behavior: The joined by
operator combines the elements of a list or property list into a text string. The split by
operator does the reverse, taking a text string and producing a list or property list from it. The word combined
may be used in place of joined
, and either with
or using
may be used instead of by
in either operator if you prefer.
When working with property lists, two separators should be used. The first indicates the text separator between elements, and the second specifies the text separator between each key and its corresponding value. To split or join a list, only a single separator is needed.
Syntax:
sourceStructure [joined | combined] [by | with | using] separator1 {and separator2}
sourceText split [by | with | using] separator1 {and separator2}
Example:
put path split by "/" into components
Example:
set newPath to components combined using "/"
Example:
put {a:1, b:2} joined with ";" and "=" --> "a=1;b=2"
Example:
split inputString by <character in ".,:;">