Say you have a FileMaker database and you have a field whose value you wish to pass to a shell script on your Mac.
The Filemaker client is running on MacOS. It doesn't matter if the Filemaker database is local (on the Mac) or the FileMaker database is hosted on a FileMaker server.
I had a "barcode" field and needed to pass that barcode to a shell script as a parameter (or argument). Well the good news is this CAN be done but the syntax is not particulary easy to figure out especially if you're not fluent in Applescript and/or FileMaker.
- I did not want the shell script to run faceless in the background. I wanted the shell script to open in Terminal so the shell script output would be visible.
- the FileMaker data table is called "test" and has a field with name "barcode" which is a Text field and the value is a simple string without any spaces.
- the Shell Script is in the user's home directory.
- the Shell script is executible:
chmod +x myShellScript.sh
In my FileMaker layout I added a button which has an "action" set to perform a script and no script Parameter is set.
In this script add a script step to "Perform Applescript"
In the FileMaker "Perform AppleScript" Options box I selected "Calculated AppleScript" and specified the following calculation:
"tell application \"Terminal\"¶" &
"activate¶"&
"do script \"$HOME/myShellScript.sh "& test::barcode & " \"¶"&
"end tell"
Specify Calculation Screenshot:
in the above "calculation" I have mostly applescript carefully quoted and with paragraph marks and ampersands to join lines.
I'm starting the Filemaker script with a button but you could start it however you like in FileMaker.
Button Setup screenshot:
Script Workspace screenshot:
- in the Applescript there is a
do script
step. Note this is a Terminal specific command which I found in the Terminal Applescript dictionary. Don't confuse this step with the similarly named Applescript commanddo shell script
- Out of Scope for this project was any automatic returning of data or status from the shell script back to FileMaker. I understand there are ways to do this but I did not need to for this use case.
- Claris Community - Using a variable within an AppleScript within a FileMaker script Thanks nicolai from 2017
- Claris Community - Sending FileMaker variables to perform applescript function 2018
- Claris Community - Using FileMaker Variable in an AppleScript 2017
- Apple Developer Technical Note TN2065 do shell script in AppleScript
- Mac Automation Scripting Guide: Calling Command-Line Tools
Initial date: 2023-01-29