执行Adobe InDesign .jsx脚本

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>
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。

非常完美地运行!谢谢! - Syjin

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

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


我在阅读时遇到了一些困难,我应该把我想要启动的脚本(PrintCard.jsx)放在哪里? - jmituzas
var theScriptFile = new File("/绝对路径/to/PrintCard.jsx"); 但是...你可能需要绝对路径...Adobe应用程序对相对路径的处理方式可能不同;你必须通过InDesign实验,看看是否可以使用new File("../PrintCard.jsx")或类似方法;如果可能,请尽量避免使用绝对路径。 - david van brink
哈哈哈,我应该再仔细读一遍,因为你说了:new File("/path/to/file.jsx");——对此我很抱歉... - jmituzas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接