Calling an OS X bash/shell script from a FileMaker script using AppleScript | The Philadelphia FileMaker User Group – serving the Pennsylvania, New Jersey and Delaware Region

Calling an OS X bash/shell script from a FileMaker script using AppleScript

Published on June 28, 2013. 0 Comments

Sometimes you have a FileMaker script that needs the OS to take care of something before it can proceed. Windows can execute a batch script using the Send Event script step:

cmd /c c:\batchfile.bat param1 param2

And on the Mac you have the ability to integrate with AppleScript, but what about running a shell/bash script? Unfortunately, it’s not as easy to have FileMaker call a shell script directly. If you have a prefab shell script that you would like to run from FileMaker (or, like me, are just more comfortable with shell script than you are with AppleScript), re-coding it in AppleScript might not be the easiest option. And while FileMaker Server can run a bash script as part of a scheduled task, getting FileMaker Pro to trigger your shell script directly can be a bit trickier.

Let’s say we have a shell script file writeparams.sh in the folder /Users/rstory/Desktop/test folder/ and the script takes 2 parameters and writes them out to a file called result.txt to the desktop. The script is as follows:

#!/bin/bash

col1=$1

col2=$2

cd ~/Desktop

echo "$col1 $col2" > result.txt

exit

So nothing fancy, and certainly nothing that would require shell scripting to accomplish, but the important thing here is that this script is a bash script, and it takes a couple of parameters. (This could easily be an ftp script, or something a little meatier, but I’m going to keep this simple).

I’ve been trying to get FileMaker to call the shell script directly using the Send Event script step the same way I might call a batch script, but couldn’t quite get the trick of it. After digging through the internet for a bit, I offer the following solution. We’re going to Perform AppleScript and use a variable in a Calculated AppleScript. For ease-of use, we’ll load the text of the AppleScript into the variable $as first, where $as reads as follows:

via Calling an OS X bash/shell script from a FileMaker script using AppleScript | The Philadelphia FileMaker User Group – serving the Pennsylvania, New Jersey and Delaware Region.

Liked Liked
Need FileMaker Development Help? Or to purchase FileMaker Software?
Contact FM Pro Gurus for help