Skip to content

Instantly share code, notes, and snippets.

@thomasjao
Created February 23, 2014 13:21
Show Gist options
  • Save thomasjao/9171397 to your computer and use it in GitHub Desktop.
Save thomasjao/9171397 to your computer and use it in GitHub Desktop.
// SIMPLE VARIABLE ASSIGNMENT
// Using syntax: set ... to ...
set a to 1 -- set a as an integer object with value 1
set PI to 3.14159 -- set PI as a real object with value 3.14159
set b to "A string" -- set b as a text object with value "A string"
set c to {"Thomas", "Sally"} -- set c as a list object contains two items: "Thomas", "Sally"
set d to {name: "Thomas", sex: "male"} -- set d as a record object with two properties with values
// To get variable type, in AppleScript, we name variable type as "class"
class of a -- return "integer"
class of PI -- return "real"
class of b -- return "text"
class of c -- return "list"
class of d -- return "record"
// Together, AppleScript has Number class served as synonym for either real or integer
// These four classes "Number", "Text", "List" and "Record" are fundamental classes of AppleScript
// In real application, there can be other classes defined by applications. Like "dir", "file" etc.
// ASSIGN VERIABLE WITH EXPRESSION
// Expressions are classes linked with operators with results
set a to 1 + 2 -- Now a contains is assigned as 3
set b to "A " & "string" -- Now b contains is "A string", use "&" to concatenate two strings
set c to {"Asia", "Europe"} & {"Africa"} -- Now c contains {"Asia", "Europ", "Africa"}
set d to { name: "Thomas", sex: "male" } & { id: "2502" } -- Now d contains {name:"Thomas", sex:"male", id: "2502"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment