Satimage Previous | Next
Smile's persistent context
Home Documentation Smile AppleScript terminals Using AppleScript in Smile Smile's persistent context  
  • Smile maintains a global context for the whole Smile session - that is, until you quit Smile.
  • Scripts that you run in an AppleScript terminal run in that context.
  • Any variable that you define in an AppleScript terminal is persistent, it is available from any AppleScript terminal (except if the window targets an application) until you quit Smile.
    This gives sense to running a script line by line.
Now on we assume that you know what "running (or compiling) a line/a script/a handler in an AppleScript terminal" refers to, as is described in the page about the AppleScript interpreter.
Examples
To change the value of any variable, run in any AppleScript terminal a line such as below.
set the_variable to 2
To read the value of any variable, run such a simple line as below.
the_variable
The handlers that you compile in AppleScript terminals are also persistent and available from any other AppleScript terminal. Compile the following handler in an AppleScript terminal.
on bip()
    beep 2
end bip
The handler is now available globally: you can run the following in any AppleScript terminal.
bip() -- will beep twice
Referring to a variable of the context in a handler defined in an AppleScript terminal
In an AppleScript terminal, to use in a handler a variable which was previously defined, you must explicitly declare it as a global variable. The following block:
on bip()
    beep the_variable
end bip
will compile correctly but will trigger an error when invoked:
"The variable the_variable is not defined"
To explicitly declare the_variable, use the global keyword.
on bip()
    global the_variable
    beep the_variable
end bip
Version française
Copyright ©2008 Paris, Satimage