• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AppleScript to JavaScript for InDesign Package

Participant ,
Apr 27, 2018 Apr 27, 2018

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

2.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

Moving to InDesign Scripting forum

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 01, 2018 May 01, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 06, 2018 May 06, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Is there anyone to help me out, please.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

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

I close this thread here

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines