1 Reply Latest reply on Dec 9, 2013 3:32 PM by ophello

    Applescript: Packaging and exporting PDFs for multiple files -- need some tweaks

    ophello Level 1

      I found and tweaked a droplet script that isn't quite working right. I am hoping for some help with getting it to work the way I want. I tried and failed to learn to do this myself. Your help is greatly appreciated!

       

      Here's an example: I drag two files called "filename.indd" and "filename2.indd" onto the droplet. The script I have right now will output the packages and PDFs into the following folder structure:

       

      export folder

           filename folder

                filename.pdf

                filename folder

                     filename.indd

                     [Package contents]

           filename2 folder

                filename2.pdf

                filename2 folder

                     filename2.indd

                     [Package contents]

       

       

      Here's the folder structure I need (using a dialog box or script that intelligently knows that the directory to save in is the same as the files I dragged on to the droplet would be amazing):

       

      dialog box to choose new directory set to baseFolder

      or

      baseFolder <---- set to the current directory of the files I dragged onto the droplet

           filename folder

                filename.indd

                [Package contents]

                PDF folder             <--------new folder "PDF" created

                     filename.pdf

           filename2 folder

                filename2.indd

                [Package contents]

                PDF folder             <--------new folder "PDF" created

                     filename2.pdf


       

      Here's a script I found and modified:

       

      ------

      property baseFolder : (path to desktop as text) & "exports:"

       

      on open mgItems

                repeat with mgThisItem in mgItems

                          tell application id "com.adobe.InDesign"

                                    try

        open mgThisItem

                                              set mgDocName to name of active document

                                              set text item delimiters of AppleScript to ".indd"

                                              set mgShortName to text item 1 of mgDocName

                                              set targetFolderPath to my createFolder(mgShortName)

                                              set text item delimiters of AppleScript to ""

                                              set mgPackageFilePath to targetFolderPath & mgShortName as string

                                              set mgProofFilePath to mgPackageFilePath & ".pdf" as string

                                              set properties of PDF export preferences to properties of PDF export preset "[Smallest File Size]"

                                              tell the active document to export format PDF type to mgProofFilePath without showing options

                                              tell the active document to package to mgPackageFilePath with copying fonts, ignore preflight errors, copying profiles, updating graphics, including hidden layers, copying linked graphics and creating report

        close active document saving no

                                    on error e

        display dialog e

                                    end try

                          end tell

                end repeat

                display dialog "PDFs created and InDesign file packaged"

      end open

      on createFolder(nameString)

                set macFolderPath to baseFolder & nameString

                do shell script "mkdir -p " & quoted form of POSIX path of macFolderPath

                return macFolderPath & ":"

      end createFolder

       

      ------

       

       

      Thanks very much!