Adobe InDesign .jsx script execute .jsx script
Asked Answered
G

2

5

How can I have my .jsx script when finished execute another .jsx script?

Maybe this will help understand what I am trying to do:

// WebCard.jsx file

function mySnippet(){
    //<fragment>
    var myPageName, myFilePath, myFile;
    var myDocument = app.documents.item(0);
    var myBaseName = myDocument.name;
    for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
        myPageName = myDocument.pages.item(myCounter).name;
        app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
        app.jpegExportPreferences.resolution = 96;
       app.jpegExportPreferences.pageString = myPageName;  

          switch(myPageName) {
        case "1" : myPageName = "EN FRONT WebCard";
            docType = "Web/Web Cards" break;
        case "2" : myPageName = "EN BACK WebCard";
            docType = "Web/Web Cards" break;
        case "3" : myPageName = "ES FRONT WebCard";
            docType = "Web/Web Cards" break;
        case "4" : myPageName = "ES BACK WebCard";
            docType = "Web/Web Cards" break;

    }
        fileName = group + " " + myPageName + " " + date + ".jpg";

        myFilePath = dirPath + docType + "/" + fileName;
        myDocument.exportFile(ExportFormat.jpg, File(myFilePath), false);
    }
    //</fragment>
}
//</snippet>
                // execute PrintCard.jsx file


//<teardown>
function myTeardown(){
}
//</teardown>
Greenfield answered 14/1, 2011 at 20:11 Comment(0)
P
5

You can easily include another script which will be executed at the point where you include it:

// ... Do something (will be executed before teardown script)


#include "../path/to/teardown/script.jsx" 
// the path can be absolute or relative.

This should work in InDesign from CS3 upwards.

Phototype answered 10/2, 2011 at 13:37 Comment(0)
D
3

Here's a fragment of some ExtendScript I use to launch other scripts; I've used it in After Effects, but it probably work in InDesign, too:

var theScriptFile = new File("/path/to/file.jsx");

var oldCurrentFolder = Folder.current;
Folder.current = theScriptFile.parent;

theScriptFile.open();
var theScriptContents = theScriptFile.read();
theScriptFile.close();

gCurrentScriptFile = theScriptFile;

if(doDebug)
    debugger;

// You have entered the debugger in Launcher...
// to debug the script you've launched, step
// into the eval() function below. 
//
eval( "{" + theScriptContents + "}" );

Folder.current = oldCurrentFolder;
gCurrentScriptFile = "";

The approach is to read the file and eval it. (P.S. another good tag would be ExtendScript, here.) Also see: http://omino.com/pixelblog/2007/11/15/binary-files-in-extendscript/

Dorindadorine answered 14/1, 2011 at 20:26 Comment(3)
I am having a bit of trouble reading that, where would I place the script that I would like to launch (PrintCard.jsx)?Greenfield
var theScriptFile = new File("/absolute/path/to/PrintCard.jsx"); but... you might need the absolute path... the adobe apps may behave different about relative paths; you'll have to experiment with InDesign to see if you can do new File("../PrintCard.jsx") or similar; if possible, try to avoid the absolute path I think.Dorindadorine
Hahaha I should have read it over again since you stated: new File("/path/to/file.jsx"); -- sorry about that...Greenfield

© 2022 - 2024 — McMap. All rights reserved.