8 Replies Latest reply on May 10, 2018 12:22 PM by Michel [FRIdNGE]

    AppleScript to JavaScript for InDesign Package

    Masood.Ahmad Level 1

      Hello,

       

      I need your expert help in converting my AppleScritpt to JavaScript. I'm not a script writer but I have created this small script to create packages along with the PDFs and zip it all together.

       

      Here's my AppleScript:

      with timeout of 86400 seconds

         

          tell application "Adobe InDesign CS5"

             

              set myDocument to active document

              set docName to name of myDocument

              set sourceName to text 1 thru -6 of docName

              set sourcePath to the file path of myDocument as string

             

              tell application "Finder"

                  set packFolder to make new folder at sourcePath with properties {name:sourceName & "_Package"}

              end tell

             

              tell active document

                  save myDocument

                 

                  set PrintPDF to (packFolder as string) & sourceName & ".pdf" as string

                  export format PDF type to PrintPDF using "KMMS_RRD_Print" without showing options

                 

                  set WebPDF to (packFolder as string) & sourceName & "-Web.pdf" as string

                  export format PDF type to WebPDF using "KMMS_Web Ready" without showing options

                 

                  set idmlFile to (packFolder as string) & sourceName & ".idml"

                  export myDocument format InDesign markup to file idmlFile

                 

                  package to alias (packFolder as string) copying fonts yes copying linked graphics yes including hidden layers yes copying profiles no updating graphics yes ignore preflight errors yes creating report no

                 

                  close myDocument

                 

              end tell

          end tell

         

          --Creating a zip file of the package folder and deleting the folder

          tell application "Finder"

              set theItem to packFolder as alias

              set itemPath to quoted form of POSIX path of theItem

              --set fileName to name of theItem

              set theFolder to POSIX path of (container of theItem as alias)

              set zipFile to quoted form of (theFolder & sourceName & "_Package.zip")

              do shell script "cd " & itemPath & ";zip -r " & zipFile & " *"

          end tell

         

      end timeout

        • 1. Re: AppleScript to JavaScript for InDesign Package
          Steve Werner Adobe Community Professional & MVP

          Moving to InDesign Scripting forum

          • 2. Re: AppleScript to JavaScript for InDesign Package
            S Hopkins Adobe Community Professional

            Hello,

            Wow, that is one heck of a script. Frankly, I have never used a script for packaging a document because there is so much to a package, and each one is unique. In later versions of InDesign the .idml and the .pdf are optionally included as part of the package. But, if you really want to convert your AppleScript to ExtendScript, the following is offered as a starter.

            var sourcePath;

            var myDocument = app.documents[0];

            var docName = myDocument.name;

            var filePath  = Folder.decode(myDocument.fullName);

            var lastDot = filePath.indexOf(".indd");

            if (lastDot == -1) {

                   sourcePath = filePath;

            }else {

                   sourcePath = filePath.substr(0,lastDot);

            }

            var folderPath = Folder.encode(sourcePath + "_Package");

            //PDF

            var PdfPath =  folderPath + ".pdf";

            var myPreset = app.pdfExportPresets.itemByName("[High Quality Print]");

            //var myPreset = app.pdfExportPresets.itemByName("KMMS_RRD_Print");

            var myFormat = ExportFormat.PDF_TYPE;

            myFile = new File(PdfPath);

            myDocument.exportFile(myFormat, myFile, false, myPreset);

            //WEBPDF

            var WebPath = folderPath + "-web.pdf";

            myFile = new File(WebPath);

            myFormat = ExportFormat.INTERACTIVE_PDF;

            myDocument.exportFile(myFormat, myFile);

            //IDML

            var IdmlPath = folderPath + ".idml";

            myFile = new File(IdmlPath);

            myFormat = ExportFormat.INDESIGN_MARKUP;

            myDocument.exportFile(myFormat, myFile);

             

            Notice that I used [High Quality Print] for preset as I don't have yours. Also added test for file name extension for original document. Also: On the web are some posts that work with zipping files using JavaScript.

            Hope this helps.

            • 3. Re: AppleScript to JavaScript for InDesign Package
              Masood.Ahmad Level 1

              Thanks Hopkins for the suggestions, much appreciated.

               

              I'm aware that InDesign gives me the flexibility to package the files in one go including idml and pdf. However, it didn't give me the surety that a user will select the correct preset everytime and won't forget to tick the required checkboxes. Secondly, the default mechanism only exports one pdf at a time and it also don't allows a user to rename a file while exporting. It also don't allow to keep my idml, print pdf, low Res pdf, Web pdf etc in separate folders. And not to mention the zipper at the end.

               

              I tested your code and it successfully exported the pdfs and the idml with "_Package" as suffix to these files. All the three files get exported to the source folder of the InDesign file. It misses the package part.

               

              As per my AppleScript, all the exported items must go in a folder. The folder name should be InDesignFileName_Package.

               

              Last but not the least, I'm not a script writer. The only thing I know is to manipulate the code.

               

              Thanks again for your time and support.

              • 4. Re: AppleScript to JavaScript for InDesign Package
                S Hopkins Adobe Community Professional

                Hi,

                I understand your reasoning for wanting to use a script. Not having had the experience writing a script for packaging, I did not want to lead you astray. I will continue to look for documentation toward that end. As to saving the files in a folder named InDesignFileName_Package, involves a little more code. Try this:

                 

                Change the code following the creation of the variable sourcePath in the if statement to read:

                //make the sourcePath variaable into an object reference, not a string

                var folderPath = Folder.encode(sourcePath + "_Package");

                //Create new Folder object

                var newFolder = new Folder(folderPath);

                //create the folder if one does not exist;

                if (!newFolder.exists) {

                  alert ("creating folder");

                  newFolder.create();

                } else {

                  alert ("Folder exists");

                }

                //change object reference to a string

                var newFolderPath = Folder.decode(folderPath);

                //PDF

                var PdfPath = Folder.ecode(newFolderPath + "/" + docNaame + ".pdf");

                var myPreset = app.pdfExportPresets.itemByName("[High Quality Print]");

                //var myPreset = app.pdfExportPresets.itemByName("KMMS_RRD_Print");

                var myFormat = ExportFormat.PDF_TYPE;

                myFile = new File(PdfPath);

                myDocument.exportFile(myFormat, myFile, false, myPreset);

                 

                 

                //Follow the same pattern for WEBPDF and IDML. Now, to discover how to do the package.

                Cheers.

                • 5. Re: AppleScript to JavaScript for InDesign Package
                  Masood.Ahmad Level 1

                  Thanks S. Hopkins, for your valuable inputs. These are the good starting points for any fresher. Since I'm not a script writer, I've to struggle a lot to get the desired output. Right now, I'm finding it hard to get the things right.

                   

                  Can anyone please help me to achieve what I'm looking for.

                  • 6. Re: AppleScript to JavaScript for InDesign Package
                    Masood.Ahmad Level 1

                    Is there anyone to help me out, please.

                    • 7. Re: AppleScript to JavaScript for InDesign Package
                      Masood.Ahmad Level 1

                      I was in the impression that this is easily achievable but it seems that it is extremely difficult.

                       

                      I close this thread here

                      • 8. Re: AppleScript to JavaScript for InDesign Package
                        Michel [FRIdNGE] Level 4

                        An advice [for all and, for you, it's not the first time]:

                         

                        Say you're going to pay for fixing your problem! … and that will be done in the day!

                         

                        Best,

                        Michel, from FRIdNGE [… but you already know me!]