3 Replies Latest reply on Jun 27, 2014 10:33 AM by FentonJones

    Script to (if/then) determine file type and choose correct program to open and print file (within...

    AnthonyTesoriero

      Title

      Script to (if/then) determine file type and choose correct program to open and print file (within batch sequence)

      Post

           I have culled together an applescript that is running within a filemaker script with great help from the community and other board posts to effectively batch print a list of files exported from filemaker containers to a folder called "print" on my desktop. 
            
           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.
            
           ***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.*** 
            
           (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.)
            
           Below is my current working applescript code.*(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.*
            
          `set myFolder to (path to desktop folder as text) & "Print:"`set myfiles to list folder myFolder without invisibles``repeat with myfile in myfiles`set mycurrentfile to ((myFolder as string) & (myfile as string)) as stringbatchprint(mycurrentfile)`end repeat``on batchprint(mycurrentfile)`tell application "Adobe Acrobat Pro"activate -- bring up acrobatopen 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 1click 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 1end tellend tellend tellend tellend telltell application "Finder" -- to move the printed file out set x to ((path to desktop folder as text) & "Printed PDFs:")if alias x exists thenbeepelsemake new folder at the desktop with properties {name:"Printed PDFs"}end ifmove alias mycurrentfile to folder "Printed PDFs"end tellend batchprint`
            
            
           Attached is a screenshot of the whole FM script...

      FM.jpg