8 Replies Latest reply on Apr 26, 2015 8:56 AM by steve_ssh

    Pass FileMaker Data to BASH Script

    JFWX5

      Hi,

       

      Using this Bash script for setting scanning profiles:

       

       

      #!/bin/bash

       

       

      if [ $number = "1" ]; then

           cd /s3/

             fscanx --tiff —gray  file1

       

      fi

       

      if [ $number = "2" ]; then

            cd /s3/

             fscanx —pdf file2

       

          fi

       

      if [ $number = "3" ]; then

           cd /s3/

             fscanx --tiff  file3

       

      else

            

             cd /s3/

              fscanx --pdf —duplex file4

      fi

       

      killall Terminal

       

       

      What do I have to include in a FileMaker's AppleScript  “do shell script” command  in order to pass Document::number  to the bash script?

       

      and

       

      and what command do I need to receive that variable in the Bash script?

       

       

      Thank you

        • 1. Re: Pass FileMaker Data to BASH Script
          mikebeargie

          Technical Note TN2065: do shell script in AppleScript

           

          Filemaker string:

          "Set number to \"" & table::field & "\" do shell script etc..."

          in bash, I think you declare:

          number = ''

          at the top of your script to declare it so it can be referenced, but I'm not entirely sure it's needed if you declare the variable in the filemaker string.

           

          The rest of your bash example script referenced the named $number variable correctly. Although I'm not sure you need quotes around the numbers 1,2 and 3.

          • 2. Re: Pass FileMaker Data to BASH Script
            JFWX5

            Mike

             

            I'll try it out tonight when I have my computer and scanner.

             

            Thank you

            • 3. Re: Pass FileMaker Data to BASH Script
              JFWX5

              I created this as a calculated AppleScript based upon your last post:

               

              "Set number to \"" & Document Library::ScanType & "\"do shell script /S3/WorkingScript.sh"

               

              It  errors out in FileMaker as:

               

              Expected “given”, “with”, “without”, other parameter name, etc. but found “/”.

               

              and

               

              Unknown Error: -2741.

               

               

              Are my " & \ out of order ?

               

              Thank you

              • 4. Re: Pass FileMaker Data to BASH Script
                steve_ssh

                Hi JFWX5,

                 

                My understanding is that you wish to trigger the shell script from FileMaker (via AppleScript), and that you'd like to pass an argument to the shell script to tell it how to conditionally branch.

                 

                I'll include some sample code below that may help get you going in the right direction.

                 

                Note that I've deviated from your conditional logic a little bit, in that ,in your original code, your last block of commands would run whenever the supplied argument is not equal to 3 (including cases where the argument is equal to 1 or 2).  My hunch is that perhaps you only want to run that last block of commands as a default case when the input arg did not match any of the previous checks.  If I'm mistaken about that, my apologies for incorrectly second-guessing you on that -- it should be easy enough to change what I've got back to what you need.

                 

                Hope this helps & kind regards,

                 

                -steve

                 

                 

                Sample shell script (replace echo command with your cd and scanner commands)

                 

                #!/bin/bash

                 

                if [ $1 = 1 ]; then

                     echo 'one';

                elif [ $1 = 2 ]; then

                     echo 'two';

                elif [ $1 = 3 ]; then

                     echo 'three';

                else

                     echo 'default case';

                fi



                Sample AppleScript To Illustrate Passing an Argument to Shell Script:


                set varShellScriptArgument to 3

                set varShellPath to "'/Users/UserName/Desktop/Cool Beans/simple_test.sh'"

                set varResult to (do shell script varShellPath & " " & varShellScriptArgument)

                return varResult




                Sample FileMaker calc to generate  AppleScript based on above:

                 

                Let([

                  ~condition = Document Library::ScanType;  // Expects a numeric value

                  ~script_path = "/Users/UserName/Desktop/Cool Beans/simple_test.sh" // Edit with your path

                ];

                  List(

                    "set varShellScriptArgument to " & ~condition;

                    "set varShellPath to " & Quote( "'" & ~script_path & "'" );

                    "do shell script varShellPath & \" \" & varShellScriptArgument"

                  )

                )

                • 5. Re: Pass FileMaker Data to BASH Script
                  JFWX5

                  Steve,

                   

                  Works just the way I needed it!  Also, correcting the logic in my bash script is a great too!

                   

                  Thank you,

                   

                   

                  John

                  • 6. Re: Pass FileMaker Data to BASH Script
                    steve_ssh

                    Hi John,

                     

                    Very pleased to hear it's working well.  Thanks for posting back.

                     

                    Very best,

                     

                    -steve

                    • 7. Re: Pass FileMaker Data to BASH Script
                      Malcolm
                      Sample AppleScript To Illustrate Passing an Argument to Shell Script:


                      set varShellScriptArgument to 3

                      set varShellPath to "'/Users/UserName/Desktop/Cool Beans/simple_test.sh'"

                      set varResult to (do shell script varShellPath & " " & varShellScriptArgument)

                      return varResult


                       

                       

                      Line 2 contains single quotes within double quotes, I presume the purpose is to handle things like the space in the directory "Cool Beans"? If that's the case you may find it easier to use the applescript method "Quoted Form of", it reduces some of the quote escaping shenanigans.

                       

                      set varShellPath to quoted form of "/Users/UserName/Desktop/Cool Beans/simple_test.sh"

                       

                      malcolm

                      • 8. Re: Pass FileMaker Data to BASH Script
                        steve_ssh

                        Thank you Malcom --

                         

                        I had always seen "Quoted Form of" in other folk's scripts, but had been lazy about learning exactly what it does and how I might be able to use it.  I'm glad you've mentioned it here so I can see.

                         

                        While we're at it:  I think I can also credit you with teaching me about using List() to join the lines of my AppleScript code in a FileMaker calc.  That technique has really helped tidy things up a lot.

                         

                        Thanks for the pointers & very best,

                         

                        -steve