Adobe InDesign .jsx 脚本 执行 .jsx 脚本

发布于 2024-10-12 09:37:05 字数 1412 浏览 3 评论 0原文

完成执行另一个 .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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

來不及說愛妳 2024-10-19 09:37:05

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

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


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

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

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.

白日梦 2024-10-19 09:37:05

这是我用来启动其他脚本的一些 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/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文