5

完成后如何让我的 .jsx 脚本执行另一个 .jsx 脚本?

也许这将有助于理解我正在尝试做的事情:

// 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>
4

2 回答 2

5

您可以轻松地包含另一个脚本,该脚本将在您包含它的位置执行:

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


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

这应该适用于 CS3 以上的 InDesign。

于 2011-02-10T13:37:31.987 回答
3

这是我用来启动其他脚本的一些 ExtendScript 的片段;我在 After Effects 中使用过它,但它可能也适用于 InDesign:

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 = "";

方法是读取文件并对其进行评估。(PS 另一个好的标签是 ExtendScript,在这里。)另请参阅: http: //omino.com/pixelblog/2007/11/15/binary-files-in-extendscript/

于 2011-01-14T20:26:54.017 回答