Class FWOSAInterpreter

This class can be constructed within JavaScript. It provides an interface by which OSA scripts can be compiled, run and executed. This is most useful for allowing AppleScript to be executed from within Freeway Actions.

Note when executing the FWOSAInterpreter methods, the time-out is suspended.

The object works by having a script set in it. You build the script by a series calls to fwWrite and fwWriteln. Then you ask the object to compile the script, after which a call to fwRun will execute it.

Example 1:
The following script will allow the user to locate a file and that file will then be executed as an AppleScript.

// locate the file with the AppleScript in it 
var theFile = new FWFile; 
if ( theFile.fwLocateOld('Locate AppleScript File','TEXT') && theFile.fwOpen('read')) 
{ 
    // create the object to interpret the script 
    var osa = new FWOSAInterpreter; 
    // read the text 
    var text = theFile.fwRead(theFile.fwAvailable); 
    // set the text in the OSA interpreter 
    osa.fwWrite(text); 
    // compile it 
    osa.fwCompile(); 
    // run it 
    var result = osa.fwRun(); 
    // if there are some results put them in an alert 
    if (result && result != '') 
    alert(result) 
} 

Example 2:
This example shows an action with a small amount of AppleScript written as markup. This markup is then executed in the OSA Interpreter. It provides the easiest method of adding AppleScript, which is generally a large amount of text, to an Action.

<action-markup custom name="osa"> 
    tell application "FileMaker" display dialog (&param;) 
    end tell 
</action-markup> 

<action-javascript> 
function fwATContent() 
{ 
    var osa=new FOSAInterpreter; 
    var text= fwMarkups["osa"]; 
    fwSubstitute(text); 
    osa.fwWrite(text); 
    osa.fwCompile(); 
    alert(osa.fwRun()); 
} 
</action-javascript> 

Properties (2)

fwIsCompile()

Has the script been compiled? Boolean

fwScriptType

This is the type of script denoted by a 4 char code, by default it is AppleScript. String (4 char)

Methods (5)

fwClear()

Clear the current script.

fwCompile

Compile whatever script is in the object. After compiling, the next time you call fwWrite it will first clear the current script.

fwRun()

Run the current script. If the script has not been compiled then it will be compiled at this point.

fwWrite(string[,string…])

This will add the arguments as a concatenated string into the script object. One or more strings

fwWriteln([string[,string…]])

This will add the arguments as a concatenated string into the script object, Zero or more strings followed by a carriage return.


Register or log in to view or add comments.

FreewayCast

Learn by watching! Screencasts show you how to do it in Freeway. Visit FreewayCast today!