Skip to main content
Inspiring
April 27, 2018
Question

AppleScript to JavaScript for InDesign Package

  • April 27, 2018
  • 2 replies
  • 2582 views

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

This topic has been closed for replies.

2 replies

Inspiring
May 10, 2018

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

I close this thread here

FRIdNGE
May 10, 2018

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!]

Steve Werner
Community Expert
Community Expert
April 29, 2018

Moving to InDesign Scripting forum

Inspiring
April 30, 2018

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.

Inspiring
April 30, 2018

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.