3 Replies Latest reply on Feb 20, 2013 10:57 AM by disabled_JustinClose

    Applescript, terminal command, and command results


      Applescript, terminal command, and command results


           I am trying to do some image encoding into base64.  I would like to accomplish all this from inside a FMP database.  I am using FileMaker (ProAd 12.03) on Mac OSX 10.6.8.

           What I have come up with so far:

              There is terminal command that will do the encoding:  openssl

              AppleScript can call a terminal command, and also set a cell value

           I would like to create an AppleScript that IDEALLY would pull the image from a container field in the current record, encode it, and use the result to set another field in the same record to the encoded value.

           I can get the AppleScript part to work, if I edit it in AppleScript Editor:

                do shell script "openssl base64 -in /Users/justin/Documents/shell_scripts/candycane.png"

           This results in the output just going to stdout, which is fine.  I also had a version of the command that output to a file in the file system, but then that would require importing that text file back into FMPro.  Maybe that is easier, but it seemed more elegant to just take the raw result and set that to a field.

           So this is the script that I am fiddling with inside FMPro in a 'Perform AppleScript' script step.  It currently just uses an existing file in the operating system as the input; if someone has ideas on how to take the contents of the container field (an image file) in this record as the input to the AppleScript, that would be appreciated.  The destination field name in the current record is "b64_encoded".

      "set encoded to do shell script 'openssl base64 -in /Users/justin/Documents/shell_scripts/candycane.png'
      set cell \"b64_encoded\" of current record to encoded"

           I keep getting syntax type errors, however.  I am, obviously, not real sure how to correctly integrate the AppleScript script step into a FMPro calculation box of a script step.




        • 1. Re: Applescript, terminal command, and command results

               It sounds like you have "Native AppleScript" checked. This may be better handled,  especially when running shell scripts, to use Calculated AppleScript.

          • 2. Re: Applescript, terminal command, and command results

                 I have tried both methods and get similar results (i.e. error messages about syntax)

            • 3. Re: Applescript, terminal command, and command results

                   I finally got things figured out.  Here is what I ended up with in my script:


              #Some ideas and syntax help gotten from:
              #From FMForums ( http://fmforums.com/forum/topic/87573-upload-contents-of-container-field-to-ftp-mac-os-applescript-technique/? hl=applescript):
              #Can't be locking the record out...
              Commit Records/Requests
              Set Variable [ $FileName; Value:GetAsText (Base64_Results::Image_c) ]
              Set Variable [ $DeskPath; Value:Get(DesktopPath) ]
              Set Variable [ $PathIn; Value:$DeskPath & $FileName ]
              #   Terminal command doesn't like the volume name in the path, so remove….
              Set Variable [ $UnixPath; Value:Middle ( $DeskPath ; Position ( $DeskPath ; "/" ; 1 ; 2 ) ; Length( $DeskPath ) ) & $FileName ]
              Export Field Contents [ Base64_Results::Image_c; “$PathIn” ]
              Set Variable [ $Script; Value:"set var_b64Result to do shell script \"openssl base64 -in " & $UnixPath & "\" "& ¶ &
              "set cell \"b64_encoded\" of current record to var_b64Result" ]
              Perform AppleScript [ Calculated AppleScript: $Script ]

                   I did end up with using 'calculated result' in my AppleScript step, but had to massage the inclusion of double quotes and the like into the terminal command.  Seems to work well now! 

                   --  J