bBox_Applescript( mode; script {; handler; param1; param2} )

script step: bBox Applescript [ Script; Handler ]

parameters:
 mode: currently not used
 script: a string that will evaluate to a valid AppleScript script
 handler: subroutine name that should be called (optional)
 param1: first parameter to pass to handler (optional)
 param2: second parameter to pass to handler (optional)result: string representation of data returned by the Applescript script


result:
 string representation of data returned by the Applescript script


error:
 bBox_LastError ("applescript")

Compile and run an AppleScript script, using the script’s return value as the function’s result. If no return value is given then a “?” is the result.

You can specify the first optional parameter and not specify the second. In other words:

Set Field [
 DEMO::output_gt;
 bBox_Applescript (
 DEMO::mode_gn;
 DEMO::script_gt;
 "my_handler";
 "1st and only parameter to subroutine my_handler"
 )
]

Text given in parameters with AppleScript will be encoded using UTF-8 character encoding, which may be a problem in a few cases when passing text whose language requires the use of 16-bit characters. However, script text and output use UTF-16.

If using this function as part of a server-side script (including with Perform Script on Server) most commands requiring a UI will not work. This is because there is no window manager or Finder to “tell”, and you will not be able to launch or activate applications, unless you can be certain that the same user account running the FileMaker script is also logged in. However, this is not recommended.

String results will be enclosed in double quotes. If expecting a numeric result, wrap the AppleScript call in a GetAsNumber function to get the expected result, like so:

GetAsNumber (bBox_Applescript( 0; "(1+1)" )) = 2

Unlike the function, the script step does not accept parameters, only an Applescript handler (function) name.

––––––––––

bBox Functions

bBox Wiki