Global and local variables, and script properties
In AppleScript, variables are not declared using a data type. In fact, you don't declare them at all unless you want to create global variables or script properties. Global variables have scope that includes the top-level script and every handler. Script properties, usually called properties, are similar to global variables, but they have a defined initial value and they persist between script runs.
You can include several global variables on the same line, separated by commas, and preferably at the top of the script, as shown in the following example:
global var1, var2
You also declare and define properties at the top of the script, giving each its own line, as shown in the following example:
property prop1 : "whatever" property prop2 : 3
You can declare ordinary variables as local, but you are not required to because they are local by default. They are defined only for the handler or the top-level script in which they occur, and remain unknown to other handlers. However, top-level variables defined without a declaration, though local, have retention and other issues.
Changing data types and releasing object references
You can easily change the value of a variable from one data type to another, as shown in the following example:
set a to 3 set a to "camel" tell application "Microsoft Word" to ¬ set a to paragraph 1 of active document
You don't have to release object references in AppleScript, which means that at the end of a script, you don't have to reset a variable whose value is an application reference to
Nothing, or something similar.
You can change the data types of variables and escape releasing object references because AppleScript has automatic garbage collection and cleans up after itself. You don't have to worry about memory issues or disposal.


