4 Replies Latest reply on Jun 17, 2009 9:05 AM by RickWhitelaw

    Passing an FM variable to Applescript?

    RickWhitelaw

      Title

      Passing an FM variable to Applescript?

      Post

      Hi,

       

      I have a script that saves a record as PDF and sets the title to the value of $TITLE. What I'm trying to do is reduce the file size. So . . . I wrote a workflow (and saved it as an application)in Automator that gets the selected file and passes it to the next step, which is a Quartz Filter. This works fine and reduces most PDF files to 1/3 the original size. The only problem is scripting the selection of the saved PDF file. I use a Perform Applescript step, something like "tell application "Finder" to open application Quartz filter". If the PDF file on my desktop is highlighted (selected) manually this works fine. However, it seems that I should be able to precede this script step with another that selects the file by name, which means I need to pass the variable $TITLE to Applescript. I've written hundreds of scripts in FM but this Applescript problem has me stumped. I'm sure it's very simple.

       

      RW 

        • 1. Re: Passing an FM variable to Applescript?
          FentonJones
            

          Script variables are relatively new to FileMaker, and its AppleScript dictionary has not been updated since they were added. So, the AppleScript implementation simply cannot see them. There are 2 ways to deal with it.

           

          1. Write the entire AppleScript as a FileMaker calculation,* and use the (•) Calculated AppleScript option (instead of Native AppleScript). This requires escaping quote marks (\"), etc.. But then your $variable will be evaluated into its value before AppleScript even sees it. So it will work. Kind of a PITA if your script is long and involved; but it sounds like yours isn't.

           

          2. Use a global field instead of a script variable. 

           

          *In the AppleScript calculation box, not as a FileMaker field, else you'd have to use a global $$variable. You can use Data Viewer to see if the calculation is correct.

          • 2. Re: Passing an FM variable to Applescript?
            RickWhitelaw
              

            Fenton,

             

            Thanks for your reply. I wrote a simple Applescript to solve the problem. I've read quite a few posts bemoaning the size of the PDF files created by Filemaker. This little AppleScript reduces the size to around 1/3:

             

            Calculated AppleScript:

             

            "tell application \"Finder\"¶

            activate¶

            select document file" & " "&Quote(GetAsText($TITLE)) &" "& "of folder \"Desktop\" of folder \"Rick\" of    folder \"Users\" of startup disk¶

            run application \"Quartz Filter\"¶

            end tell" 

             

             

            This is a Perform Applescript script step meant to run in the script after the document has been saved as PDF. $TITLE is a local variable and a concatenation of elements from the parent record that identify the document. The "application" "Quartz Filter" is simply an Automator Workflow saved as an application. It consists of two steps: 1) "Get selected Items" which passe the item(s) to the next step and 2) Apply Quartz Filter to PDF Documents with "Reduce File Size" selected. The file path should also be the result of a calculation based on the User Account, which I have yet to do.

             

            RW 

            • 3. Re: Passing an FM variable to Applescript?
              hiatts
                

              just an idea... if you dont need this to be 100% automated...

               

              why dont you attach the automator to a folder as a folder action... that executes when you drop files in the folder... saves any scripting and passing filenames etc. 

              • 4. Re: Passing an FM variable to Applescript?
                RickWhitelaw
                  

                Hi and thanks,

                 

                The idea was to completely automate the process and I have. I made one small change (home) to make the script useable by any logged-in user and added a one second delay to allow the external application to execute before closing the finder window "Desktop". It reduces file size from 230K to around 60-70K. I may take this further and use Applescript or Automator to script the creation of the PDF, which is currently handled by a Filemaker script step. That way it should work in a runtime version (on Mac OS anyway). Currently, without this capacity, I'm not interested in using a runtime. I produce a lot of PDF files and don't want to use the OS Print dialog for the task.

                (quote)

                "tell application \"Finder\"¶

                activate¶

                select document file" & " "&Quote(GetAsText($TITLE)) &" "& "of folder \"Desktop\" in home¶

                run application \"Quartz Filter\"¶

                delay 1¶

                close Finder window\"Desktop\"¶

                end tell"

                (end quote)