Article ID: 108622 - Last Review: October 15, 2003 - Revision: 2.1 How to Use AppleScript Scripts to Return Values to FoxProThis article was previously published under Q108622 SUMMARY
The AppleScript language supports a RETURN statement that allows the author
of a script to send a result back to the calling procedure. The calling
procedure can be a FoxPro program, command, or procedure. Examples are
provided below.
NOTE: AppleScript is manufactured by a vendor independent of Microsoft; we make no warranty, implied or otherwise, regarding this product's performance or reliability. MORE INFORMATION
A script, which is a series of one or more commands supported by the
AppleScript language, is analogous to a procedure written in Microsoft
FoxPro or some other high-level language. Like procedures, a script can
communicate with a calling program by returning a value to it. To run a
script from within Microsoft FoxPro for Macintosh, use the following
command syntax:
RUNSCRIPT <AppleScript> [TO <variable> | <field>]
If the script terminates with a RETURN statement, that value is returned to
FoxPro and stored in the optional parameter to the RUNSCRIPT command.
The following example is an elementary AppleScript script that simply returns a Boolean, or logical, value:
return TRUE
The following example illustrates how FoxPro for Macintosh can store a
value to a variable named retVal from an AppleScript script named MyScript:
RUNSCRIPT HD:Scripts:MyScript TO retVal
Although AppleScript supports a variety of extended types, or classes, such
as lists, records, and aliases, FoxPro transforms them into simple
character expressions when storing them.
Since only a single value can be returned from an AppleScript script and FoxPro for Macintosh does not support the passing of parameters to an AppleScript script, a character expression delimited with commas or some other value is recommended. Since AppleScript supports the list as a standard class, it makes sense to take advantage of it to build a list of return values. For example, the following AppleScript returns multiple values to the calling program by building a list object:
RUNSCRIPT MyScript2 TO retVal
The list is returned to FoxPro as a character string delimited with commas.
In this case, the character expression "First, Last" is returned, and the
individual values can be returned using FoxPro's arsenal of string-
manipulation functions such as SUBSTR() and AT(). The following FoxPro code
snippet extracts the elements from retVal and stores the individual values
to new variables:
| Article Translations
|
Back to the top
