title: Applescript to (if/then) determine file type and choose correct program to open and print file (within batch sequence)
body: <p>I have culled together an applescript with great help from @chuck and other board posts to effectively batch print a list of files exported from filemaker containers to a folder called "print" on my desktop. </p>
  
  <p>The problem I'm running into now is some of those container exports are not PDF (its a mix of Jpg, PNG, Tif and PDF) and will not open using acrobat (using preview for the PDF or any other PDF  viewer is out of the question for a myriad of reasons)... This problem is effectively shutting down the work flow because of error messages from acrobat that must be manually clicked off before the script will proceed to the next file.</p>
  
  <p><strong><em>My question is can applescript be commanded to determine the file type first and choose a different program to open the document with and trigger the print command and close window before moving onto the next document in the sequence.</em></strong> </p>
  
  <p>(i.e. if .pdf then use acrobat print close window, if not use preview to open file, print close window, repeat until all files have been printed.)</p>
  
  <p>Below is my current working code.<em>(FYI) This script is running within a filemaker script that is creating the "Print" folder on the desktop and exporting the container fields to the folder.</em></p>
  
  <pre><code>`set myFolder to (path to desktop folder as text) &amp; "Print:"
  </code></pre>
  
  <p><code>set myfiles to list folder myFolder without invisibles</code></p>
  
  <p><code>repeat with myfile in myfiles</code></p>
  
  <pre><code>set mycurrentfile to ((myFolder as string) &amp; (myfile as string)) as string
  batchprint(mycurrentfile)
  </code></pre>
  
  <p><code>end repeat</code></p>
  
  <p><code>on batchprint(mycurrentfile)</code></p>
  
  <pre><code>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 ((path to desktop folder as text) &amp; "Printed PDFs:")
      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
  </code></pre>
  
  <p>end batchprint`</p>