title: How to script printing of multiple layouts from filemaker pro plus multi page PDFs from containers in sequence
body: <p>We need a script that will print a multipage PDF within a printing sequence from filemaker pro.</p>
  
  <p>We use a filemaker PRO database that is rough around the edges but general works for our processes. We are trying to automate some workflows but continue to run into gaping glitches that have stumped us and held back our productivity with this application. </p>
  
  <p>It appears that filemaker is unable to print multipage PDF's that are stored in it's container fields. Further complicating the mater filemaker pro for mac has a frequent problem crashing on larger files when using Adobe as the default web plugin to view PDF files, thereby making it necessary to default to using "preview" for mac as the default reader. </p>
  
  <p>The problem with using preview though is that when certain documents were created originally using acrobat such as forms or PDFs with embedded pics, Preview will fail to recognize the data on the forms or the embedded pics thereby rendering a blank page, making its necessary to use Acrobat only to print the documents...</p>
  
  <p>Our solution requires us to batch print large amounts of documents from found sets within our database.</p>
  
  <p>Each record has a series of layouts that must be printed in a specific order and a collection of attachments (container fields) that must also be printed.</p>
  
  <p>Currently we are able to batch print all the filemaker layout documents in the proper sequential order for a batch, (Average 20 records per batch, each record having 10 pages = 200 Pages (without corresponding attachments) </p>
  
  <p>Because of filemaker's limitations however we must then manually go into each record, open each relevant attachment, right click to "open as" Adobe PDF, execute a print command, manually close the adobe window, manually close the filemaker container window and repeat for each relevant attachment per record.... As you can imagine this becomes very time consuming. </p>
  
  <p>To make matters more complicated we then have to hand collate the documents to insert the separately printed container PDF's and associate them with the other printed docs...</p>
  
  <p>We are trying to create scripting that will enable us to print the entire file in the proper sequential order so that it is pre collated.  (i.e. Print 5 layouts, print container 1, print 3 layouts, print container 2, print 2 layouts, print containers 3 and 4) move to next record repeat...</p>
  
  <p>I believe one way to solve this is to export the PDF from the container field to a watch folder that would have an applescript attached to it and automatically print.. However I have been unsuccessful in figuring out how to script a hot folder to print using the adobe engine.</p>
  
  <p>I have made hot folders that print using the default preview engine however this results in a blank document. These documents only seem to print correctly when printed from the print dialog of adobe reader or acrobat alone.</p>
  
  <p>I am open to any suggestions at this point...</p>
  
  <p>Update: I was able to create an apple script by culling together bits from other posts. This script batchprints PDFS from a folder using the acrobat pro 11 engine and moves them to a separate folder when complete... I'd like assistance in integrating this script into filemaker so that when I export a PDF from a container field it prints in sequence with the other documents from the filemaker record... Here is the script:</p>
  
  <pre><code>property myFolder : "HD:Users:User:desktop:Print:"
  
  set myfiles to list folder myFolder without invisibles
  
  repeat with myfile in myfiles
  
      set mycurrentfile to ((myFolder as string) &amp; (myfile as string)) as string
      batchprint(mycurrentfile)
  
  end repeat
  
  on batchprint(mycurrentfile)
  
      tell application "Adobe Acrobat Pro"
          activate -- bring up acrobat
          open alias mycurrentfile -- acrobat opens that new file    
          tell application "System Events"
              tell process "Acrobat"
                  click menu item "Print..." of menu 1 of menu bar item "File" of menu bar 1
                  click button "Print" of window "Print"
                  tell application "System Events"
                      tell process "Acrobat"
                          click menu item "Close" of menu 1 of menu bar item "File" of menu bar 1
                      end tell
                  end tell
              end tell
          end tell
      end tell
  
      tell application "Finder" -- to move the printed file out 
          set x to (("HD:Users:User:desktop:Printed PDFs") as text)
          if alias x exists then
              beep
          else
              make new folder at the desktop with properties {name:"Printed PDFs"}
          end if
          move alias mycurrentfile to folder "Printed PDFs"
  end tell
  
  
  end batchprint
  </code></pre>