links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Applescript Plugin
Last updated at 12:33 pm UTC on 8 July 2001


Among the goodies distributed beginning with the 2.6test version of Squeak is a robust Applescript plugin, permitting full access to Applescript from within Squeak. With Applescript, for example, you can provide programmatic to a vast majority of MacOS technologies, control the Finder and perform printing tasks.


To use the new plugin, you need a MacOS-based Squeak, upgraded to version 2.6test, and the plugin file, which you can download from here.

To get the plugin up and running:

  • Place the plugin in the same folder as the Squeak executable.
  • Make sure your Squeak is fully upgraded to the current 2.6test version.
  • Execute the doIt: "Applescript initialize"

    Executing Applescript in Squeak

    Thereafter, you can execute Applescripts with the simple command:

       Applescript doIt: 'beep 3'

    Compiled Applescripts

    Unfortunately, this process requires the recompilation of the Applescript (as well as the loading of the compiler component) each time the command is executed. You can create a persistent Squeak object embodying the compiled script with:

       theScript := Applescript on: 'say "Go, Squeak!"'

    and execute the script thereafter (much more quickly) by sending the object the message:

       theScript doIt

    Applescript Contexts

    Scripting languages are far more useful when they can retain useful state information between executions, or communicate with other scripts using that information. Applescript provides such a facility in what is called a "scripting context." By default, Squeak compiles to objects that include their own context, so that after executing:

       theScript := Applescript on: '
          property numBeeps: 0
          set numBeeps to numBeeps + 1
          beep numBeeps'

    you can execute the script with the statement.

       theScript doIt.

    However, each subsequent time you execute the statement, the script will beep an additional time. This is because the adjusted state context information is retained in the persistent Squeak object.

    Independent Contexts

    It is often useful to maintain a context independently of a script, in part to permit the script to interact with other scripts. To do so, you must compile the script so it does not include its context, by using "mode: 0," as follows:

       beeping := Applescript 
          on: 'set numBeeps to numBeeps + 1
             beep numBeeps'
          mode: 0.
       context := Applescript on: 'property numBeeps: 0'

    after which the script may be executed with the following code:

       beeping doItIn: context.

    Subsequent executions of this code will result in additional beeps. You can also permit other scripts to manipulate
    , for example as follows:

       resetting := Applescript
          on: 'set numBeeps to 0'
          mode: 0

    after which the code:

       resetting doItIn: context.
       beeping doItIn: context

    will begin beeping with a single beep.

    Other Commands

    You may find the following commands helpful or useful.

       Applescript doIt: aString mode: anInteger.
       Applescript doIt: aString in: aContext mode: anInteger
       Applescript doIt: aString in: aContext
       Applescript on: aString mode: anInteger
       aScript doItIn: aContext mode: anInteger
       aScript doItMode: anInteger