Skip to content

Instantly share code, notes, and snippets.

@ilessing
Last active February 3, 2023 01:31
Show Gist options
  • Save ilessing/67d0a8e84800b0a8a533e15ca5e1fbbc to your computer and use it in GitHub Desktop.
Save ilessing/67d0a8e84800b0a8a533e15ca5e1fbbc to your computer and use it in GitHub Desktop.
How to pass a FileMaker field value to a shell script on MacOS using Applescript

How to pass a FileMaker field value to a shell script on MacOS using Applescript

Description:

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.

Requirements:

  • 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.

Prerequisites and assumptions for my example:

  • 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

FileMaker script:

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: filemaker-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:

filemaker-button-setup-screenshot

Script Workspace screenshot:

filemaker-script-workspace-screenshot.png

Note:

  • 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 command do 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.

Reference:


Initial date: 2023-01-29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment