3 Replies Latest reply on Apr 15, 2010 6:23 AM by iBabs2

    My InDesign to PDF script ignores warnings, but I need to change that.

    iBabs2 Level 1

      Hello,

       

      I have a script here that converts InDesign Docs to PDF files.

       

      It works fine and was created to make bulk pdf's regardles of missing images.

       

      Now I want to revise it so that it does stop for missing fonts and images.

       

      This script also was built for quark and I can see where I could remove the supress all warnings dialog to remove it for the quark part, but I can't figure out where that warning is in the InDesign part to remove it.

       

      Here is the script: If anyone can help me find out where this line of code is that I could remove, so that the script does stop if there are missing fonts and images, that would be great!!

       

      property Babs_Folder : "Babs PDF Folder"
      global deskPath
      global PathToFolder
      global PathToFolder2
      global tempPictures

       


      on open thefiles
          tell application "Finder"
              activate
              set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
              if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
              set deskPath to desktop as text
             
             
              set PathToFolder to POSIX path of (deskPath & Babs_Folder)
              set PathToFolder2 to deskPath & Babs_Folder & ":"
          end tell
          my openfiles()
          say "Finished"
      end open

       

      on openfiles()
          try
              tell application "Finder"
                  repeat with LoopFiles in tempPictures
                      set foundImages to {}
                      if kind of LoopFiles = "Folder" then
                          try
                              set foundImages to files of entire contents of LoopFiles as list
                          on error
                              set foundImages to files of entire contents of LoopFiles
                          end try
                      else
                          if kind of LoopFiles is not in {"Volume", "Disk Image", "Application", "Web Internet Location", "Document", "Text Clipping"} then
                              set end of foundImages to LoopFiles
                          end if
                      end if
                      --set WorkingFile to item i of fileList
                      repeat with WorkingFile in foundImages
                          if not ((kind of WorkingFile starts with "Quark") or (kind of WorkingFile starts with "InDesign")) then
                              activate
                              display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 1
                          else
                              --Determine whether to use InDesign subroutines or Quark subroutines
                              if (kind of WorkingFile starts with "InDesign") then -- Process as InDesign
                                  my createInDesignPDF(WorkingFile, PathToFolder2)
                              else -- Process as Quark
                                  my createQuarkPDF(WorkingFile)
                              end if
                          end if
                      end repeat
                  end repeat
              end tell
          on error errmsg
              display dialog "OpenFiles." & return & errmsg giving up after 20
          end try
      end openfiles

       


      on createInDesignPDF(WorkingFile, savePath)
          set x to 0
          repeat
              if x = 0 then
                  set newpart to ""
              else
                  set newpart to " " & x
              end if
              tell application "Finder"
                  set tempname to my add_extension(WorkingFile, newpart, "pdf")
                  if not (exists file tempname in folder Babs_Folder) then exit repeat
              end tell
              set x to x + 1
          end repeat
          tell application "Adobe InDesign CS3"
              try
                  try
                      set user interaction level of script preferences to never interact
                  end try
                  open WorkingFile as alias
                  delay 2
                  repeat
                      if exists document 1 then exit repeat
                      delay 0.2
                  end repeat
                  set theProps to properties of PDF export preset "[Press Quality]"
                  set newProps to {view PDF:false, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
                  set oldProps to properties of PDF export preferences
                  set properties of PDF export preferences to newProps
                  export front document format PDF type to (savePath & tempname) without showing options
                  set properties of PDF export preferences to oldProps
                  delay 1
                  tell documents to close saving no
                  try
                      set user interaction level of script preferences to interact with all
                  end try
              on error errmsg
                  display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
              end try
          end tell
      end createInDesignPDF

       

      on createQuarkPDF(WorkingFile)
          try
              set x to 0
              repeat
                  if x = 0 then
                      set newpart to ""
                  else
                      set newpart to " " & x
                  end if
                  tell application "Finder"
                      set tempname to my add_extension(WorkingFile, newpart, "pdf")
                      if not (exists file tempname in folder Babs_Folder) then exit repeat
                  end tell
                  set x to x + 1
              end repeat
              tell application "QuarkXPress"
                  activate
                  open WorkingFile as alias with Suppress All Warnings
                  tell application "System Events" to tell process "QuarkXPress"
                      click menu item "Layout as PDF..." of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
                      delay 1
                      keystroke tempname
                      delay 1
                      keystroke "G" using {shift down, command down}
                      delay 1
                      keystroke PathToFolder
                      delay 1
                      click button "Go" of sheet 1 of window "Export as PDF"
                  end tell
                  repeat 2 times
                      delay 1
                      activate
                      tell application "System Events" to tell process "QuarkXPress"
                          try
                              if exists button "OK" of window 1 then
                                  click button "OK" of window 1
                              end if
                          end try
                      end tell
                  end repeat
                  delay 1
                  tell application "System Events" to tell process "QuarkXPress"
                      try
                          click button "Save" of window "Export as PDF"
                      end try
                  end tell
                  repeat 4 times
                      delay 1
                      activate
                      tell application "System Events" to tell process "QuarkXPress"
                          try
                              if exists button "OK" of window 1 then
                                  click button "OK" of window 1
                              end if
                          end try
                          try
                              if exists button "List Profiles" of window 1 then
                                  click button "Continue" of window 1
                              end if
                          end try
                      end tell
                  end repeat
                  delay 2
                  close front document saving no
              end tell
          on error errmsg
              display dialog "CreateQuarkPDF." & return & errmsg giving up after 20
          end try
      end createQuarkPDF

       

      on add_extension(WorkingFile, new_part, new_extension)
          try
              set this_info to info for WorkingFile as alias
              set this_name to the name of this_info
              set this_extension to the name extension of this_info
              if this_extension is missing value then
                  set the default_name to this_name
              else
                  set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
              end if
              return (the default_name & new_part & "." & the new_extension)
          on error errmsg
              display dialog "add extension " & return & errmsg
          end try
      end add_extension

       

       

      thanks!!!

      babs

        • 1. Re: My InDesign to PDF script ignores warnings, but I need to change that.
          [Jongware] Most Valuable Participant

          In Javascript, this is called "suppressing user interaction", and lo & behold: I see this phrase popping up a few times in your script:

           

          try
             set user interaction level of script preferences to never interact
          end try

           

          The "try..end try" is to suppress any errors that may happen while this command is processed -- a double safety, so to speak --, and you can safely remove all three lines in one go. Be sure not to remove any more 'try's above and 'end try's below it, only the ones immediately surrounding this one command.

           

          By the way #1: this first example sets the interaction level to "never interact". I didn't look that close, but presumably it may occur more than once, and also with a variant called "always interact" (which resets your ID back to normal). Remove all of them.

           

          By the way #2: I don't know what the "comment" sequence is for AppleScript (was it two dashes? -- like this?). Rather than simply deleting these lines, you could make them comments, so if it backfires you still can restore it. And insert a comment line above the changed lines, simply saying something like

           

          -- 14-Apr-2010: Babs removed error suppression

           

          so you (and everyone else) can tell who changed what where, some time next year when you have to change something else.

          • 2. Re: My InDesign to PDF script ignores warnings, but I need to change that.
            iBabs2 Level 1

            Hello,

            This is very helpful information. I am already home from work for the day, but will test it out first thing in the morning!!

            thanks and I will keep you posted

            babs

            • 3. Re: My InDesign to PDF script ignores warnings, but I need to change that.
              iBabs2 Level 1

              Hello,

               

              OK-I had then blew it... ;-(


              I was playing with a combination of removing (commenting out those two try areas you suggested), and that didn't do it on its own. It didn't do anything, it just said finished.


              Then I found this in the dictionary ( set alert missing images to true) and added it to the script below. See my changes in Bold.


              At one point, I was able to get the missing images dialog box. Then I don't know what happened, I think I tried to turn one of the try areas back on to test it, and then it stopped giving me that dialog box and only the one being asked in that on error errmsg - display dialog "CreateIndesignPDF." & return & errmsg giving up after 20,  was showing up.




              I commented out what I thought I had  changed, but even after compiling and re-saving, I can't seem to get the missing images dialog box to show???


              any thoughts?


              thanks!!!

              babs

               

               

              property Babs_Folder : "Babs PDF Folder"
              global deskPath
              global PathToFolder
              global PathToFolder2
              global tempPictures

               


              on open thefiles
                  tell application "Finder"
                      activate
                      set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
                      if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
                      set deskPath to desktop as text
                     
                     
                      set PathToFolder to POSIX path of (deskPath & Babs_Folder)
                      set PathToFolder2 to deskPath & Babs_Folder & ":"
                  end tell
                  my openfiles()
                  say "Finished"
              end open

               

              on openfiles()
                  try
                      tell application "Finder"
                          repeat with LoopFiles in tempPictures
                              set foundImages to {}
                              if kind of LoopFiles = "Folder" then
                                  try
                                      set foundImages to files of entire contents of LoopFiles as list
                                  on error
                                      set foundImages to files of entire contents of LoopFiles
                                  end try
                              else
                                  if kind of LoopFiles is not in {"Volume", "Disk Image", "Application", "Web Internet Location", "Document", "Text Clipping"} then
                                      set end of foundImages to LoopFiles
                                  end if
                              end if
                              --set WorkingFile to item i of fileList
                              repeat with WorkingFile in foundImages
                                  if not ((kind of WorkingFile starts with "Quark") or (kind of WorkingFile starts with "InDesign")) then
                                      activate
                                      display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 1
                                  else
                                      --Determine whether to use InDesign subroutines or Quark subroutines
                                      if (kind of WorkingFile starts with "InDesign") then -- Process as InDesign
                                          my createInDesignPDF(WorkingFile, PathToFolder2)
                                      else -- Process as Quark
                                          my createQuarkPDF(WorkingFile)
                                      end if
                                  end if
                              end repeat
                          end repeat
                      end tell
                  on error errmsg
                      display dialog "OpenFiles." & return & errmsg giving up after 20
                  end try
              end openfiles

               


              on createInDesignPDF(WorkingFile, savePath)
                  set x to 0
                  repeat
                      if x = 0 then
                          set newpart to ""
                      else
                          set newpart to " " & x
                      end if
                      tell application "Finder"
                          set tempname to my add_extension(WorkingFile, newpart, "pdf")
                          if not (exists file tempname in folder Babs_Folder) then exit repeat
                      end tell
                      set x to x + 1
                  end repeat
                  tell application "Adobe InDesign CS3"
                      try
                         --try
                          --set user interaction level of script preferences to never interact
                          --end try

                          open WorkingFile as alias
                          set alert missing images to true
                          delay 2
                          repeat
                              if exists document 1 then exit repeat
                              delay 0.2
                          end repeat
                          set theProps to properties of PDF export preset "[Press Quality]"
                          set newProps to {view PDF:false, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
                          set oldProps to properties of PDF export preferences
                          set properties of PDF export preferences to newProps
                          export front document format PDF type to (savePath & tempname) without showing options
                          set properties of PDF export preferences to oldProps
                          delay 1
                          tell documents to close saving no
                          --try
                          --set user interaction level of script preferences to interact with all
                          --end try

                      on error errmsg
                          display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
                      end try
                  end tell
              end createInDesignPDF

               

              on createQuarkPDF(WorkingFile)
                  try
                      set x to 0
                      repeat
                          if x = 0 then
                              set newpart to ""
                          else
                              set newpart to " " & x
                          end if
                          tell application "Finder"
                              set tempname to my add_extension(WorkingFile, newpart, "pdf")
                              if not (exists file tempname in folder Babs_Folder) then exit repeat
                          end tell
                          set x to x + 1
                      end repeat
                      tell application "QuarkXPress"
                          activate
                          open WorkingFile as alias with Suppress All Warnings
                          tell application "System Events" to tell process "QuarkXPress"
                              click menu item "Layout as PDF..." of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
                              delay 1
                              keystroke tempname
                              delay 1
                              keystroke "G" using {shift down, command down}
                              delay 1
                              keystroke PathToFolder
                              delay 1
                              click button "Go" of sheet 1 of window "Export as PDF"
                          end tell
                          repeat 2 times
                              delay 1
                              activate
                              tell application "System Events" to tell process "QuarkXPress"
                                  try
                                      if exists button "OK" of window 1 then
                                          click button "OK" of window 1
                                      end if
                                  end try
                              end tell
                          end repeat
                          delay 1
                          tell application "System Events" to tell process "QuarkXPress"
                              try
                                  click button "Save" of window "Export as PDF"
                              end try
                          end tell
                          repeat 4 times
                              delay 1
                              activate
                              tell application "System Events" to tell process "QuarkXPress"
                                  try
                                      if exists button "OK" of window 1 then
                                          click button "OK" of window 1
                                      end if
                                  end try
                                  try
                                      if exists button "List Profiles" of window 1 then
                                          click button "Continue" of window 1
                                      end if
                                  end try
                              end tell
                          end repeat
                          delay 2
                          close front document saving no
                      end tell
                  on error errmsg
                      display dialog "CreateQuarkPDF." & return & errmsg giving up after 20
                  end try
              end createQuarkPDF

               

              on add_extension(WorkingFile, new_part, new_extension)
                  try
                      set this_info to info for WorkingFile as alias
                      set this_name to the name of this_info
                      set this_extension to the name extension of this_info
                      if this_extension is missing value then
                          set the default_name to this_name
                      else
                          set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
                      end if
                      return (the default_name & new_part & "." & the new_extension)
                  on error errmsg
                      display dialog "add extension " & return & errmsg
                  end try
              end add_extension