5 Replies Latest reply on Nov 28, 2011 1:51 AM by karo

    A Simple Applescript to Print PDFs Issue

    StephenWonfor

      Hi

       

      Last week I had posted about FMP errors when printing a lot (200+) invoices from a looping script. Erik had suggested printing to PDF instead - works like a charm.

      Now, the next part of my problem is to get the PDFS to print automatically after the routine finishes.

      I generate the PDF names so I can pass that into an Applescript and have that Applescript print the PDF.

       

      eg.

       

      tell application "Finder"

      activate

      print document file "PersianRug.pdf" of folder "Desktop" of folder "stephen" of folder "Users" of startup disk

      end tell


      The "issue" is that the Applescript printed pdf has the top 1.3 cm cutoff (1/2" stateside). If I print the PDF normally from Preview it is fine. Quite repeatable.

      Does Applescript use something different when it prints?

       

      OSX 10.7.2.

       

      Stephen

       

      ........

       

      "C Code.

      C Code Run.

      Run, Code, RUN!

      PLEASE!!!!" = J. Frazier

        • 1. Re: A Simple Applescript to Print PDFs Issue
          sporobolus

          on 2011-11-25 15:58 StephenWonfor wrote

          tell application "Finder"

             activate

          print document file "PersianRug.pdf" of folder "Desktop" of folder "stephen" of folder "Users" of startup disk

          end tell

          *

          *

          The "issue" is that the Applescript printed pdf has the top 1.3 cm cutoff (1/2" stateside).  If I print the PDF normally from Preview it is fine.  Quite repeatable.

          Does Applescript use something different when it prints?

           

          it's not AppleScript — Finder is the issue, it prints directly without the

          benefits of Preview's guesses at page setup

           

          if Preview works reliably better, your AppleScript could open the PDF in

          Preview and tell it to print with GUI scripting; this sort of script is never

          pretty, and you need to "Enable access for assistive devices" in the Universal

          Access pref pane; it's possible this won't work on 10.7

           

           

            tell application "Preview"

             activate

             open file ((path to desktop folder as string) & "PersianRug.pdf")

            end tell

            tell application "System Events"

             tell process "Preview"

               keystroke "p" using command down

               set s to false

               -- don't press return until Print sheet appears

               repeat 10 times

                 if sheet 1 of window 1 exists then

                   keystroke return

                   exit repeat

                 end if

                 delay 1

               end repeat

               -- don't quit until printed

               repeat 10 times

                 if (name of window 1) is not "Print" and (sheet 1 of window 1 exists) is

          false then

                   keystroke "q" using command down

                   exit repeat

                 end if

                 delay 1

               end repeat

             end tell

            end tell

           

          (posting by email, watch for line wrap)

          • 2. Re: A Simple Applescript to Print PDFs Issue
            StephenWonfor

            Steve

             

            Thanks for the info.  I'll get back with results.

             

            Stephen

            • 3. Re: A Simple Applescript to Print PDFs Issue
              karo

              Hi Stephen,

               

              as Steve wrote your printing within the Finder is not the same like printing from Preview.

              Your script is like to drag and drop your pdf document directly into the printer queue (open your printer icon and you will see the list for printing).

              I think if you tried this way you will get also the 1.3 cm cutoff.

               

              If you don't want to use System Events for compatibility you can use Adobe Acrobat Pro, which is AppleScript-able.

               

              regards,

              Robert.

              • 4. Re: A Simple Applescript to Print PDFs Issue
                sporobolus

                on 2011-11-27 13:43 karo wrote

                If you don't want to use System Events for compatibility you can use Adobe Acrobat Pro, which is AppleScript-able.

                 

                i had thought the same, and i have scripted older versions of Acrobat Pro quite

                a bit, but starting with version 7 (and tested recently with version 8 and

                Adobe Reader 9) printing via AppleScript has been completely broken for me; my

                research found other people with the same unresolved problem

                 

                i haven't heard if this is fixed in more recent versions; if you have a print

                AppleScript which works with any recent version of these apps, i would

                interested to see it and know which version(s)

                 

                of course, you should be able to use the System Events approach with Acrobat

                Pro or Adobe Reader if that produces better results than Preview

                • 5. Re: A Simple Applescript to Print PDFs Issue
                  karo

                  i haven't heard if this is fixed in more recent versions; if you have a print

                  AppleScript which works with any recent version of these apps, i would

                  interested to see it and know which version(s)

                   

                  I'm sorry, I have actual no AppleScript for Acrobat. I have checked only, if it is scriptable and if it understand the print command (Acrobat Pro 9).

                  (To tell you the truth I am not a fan of Acrobat because of the clumsy interface.

                  I love more to applescript Indesign and Photoshop which seems more logical and stable to me)