Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6902 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Using Applescript, you are able to use the "do script" command. However, you are unable to pass parameters into the command from Applescript. Below I have listed a work-around for this. Please note it requires a plug-in which can trigger scripts from a field calculation. I use the free zippscript. You can get it from http://homepage.mac.com/jkornhaus/

First, Create these Global Fields in your FileMaker solution:

ApplescriptScriptName

ApplescriptScriptParameter

ApplescriptScriptAction

Next, create a layout in your solution with only the above 3 fields on it. For now, we'll call the layout name "ApplescriptGlobals"

Next, create these Scripts in your FileMaker solution:

Script #1 Name: ApplescriptShowGlobalFields

NewWindow["ApplescriptGlobals"]

GoToLayout["ApplescriptGlobals"]

AdjustWindow[Resize to fit]

Script #2 Name: ApplescriptHideGlobalFields

CloseWindow["ApplescriptGlobals"]

Script #3 Name: ApplescriptDoScript

SetField[ApplescriptScriptAction; zippScript_PerformScript( get(FileName); ApplescriptScriptName; ApplescriptScriptParameter; "Resume" )]

--Set field would differ based on plug-in

Finally, onto the Applescript.

Add this function to the bottom of your Applescript.

on ApplescriptDoScript(myName, myParameter)

tell application "FileMaker Pro"

--pop window with global fields on it b/c applescript must have the fields on the layout to be set

do script FileMaker script "ApplescriptShowGlobalFields"

--set FileMaker fields

set cell "Globals::ApplescriptScriptName" to myName

set cell "Globals::ApplescriptScriptParameter" to myParameter

--close window with global fields on it

do script FileMaker script "ApplescriptHideGlobalFields"

--run script which runs trigger script passing in name and parameter

do script FileMaker script "ApplescriptDoScript"

end tell

end ApplescriptDoScript

Now, in your appelscript, whenever you need to call a FileMaker script and pass a parameter, you can call it like this:

ApplescriptDoScript("MyScriptName", "MyParameter")

If you need to pass a value from a FileMaker field as part of your parameter, you code may look more like this..(sudo, not sure if exactly correct)

Tell Application "FileMaker Pro"

set myParam to cell "myField"

end tell

ApplescriptDoScript("MyScriptName", myParam)

The overall idea here is that you cannot direclty pass parameters into a FileMaker script from Applescript. To get around this, we create Golbal fields to hold the script and parameters. We then create a script to show a layout with the fields on it. This is because when applescript does a set cell command, the field must be on the layout. Then it closes the window and calls a FileMaker script, which uses the plug-in to call the script with the parameter. You must use a plug-in so that you can pass any string into it for the script name because in the PerformScript step in FileMaker, you must choose an exact script, and cannot make it vary.

I hope some people find this useful. We needed it to help us do some automated load-testing where we used the applescript to simulate user interaction.

Posted

This is because when applescript does a set cell command, the field must be on the layout.

Not True! Before OS X was it Layout 0 but today, is the syntax:

tell application "FileMaker Pro Advanced"

	

	set cell 1 of table 1 to "ff"

end tell

--sd

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.