InDesign - 制作一个独立的窗口,在文档中进行更正时该窗口将保持打开状态

问题描述 投票:0回答:1

var Widows_Report = new Window("dialog", "Let's Find Some Widows", undefined, {borderless: false, resizeable: false});
Widows_Report.orientation = "column";
Widows_Report.alignChildren = ["center", "top"];
Widows_Report.spacing = 10;
Widows_Report.margins = 16;

var panel1 = Widows_Report.add("panel", undefined, "Select the pages you want to search");
panel1.orientation = "column";
panel1.alignChildren = ["center", "center"];
panel1.spacing = 10;
panel1.margins = [10, 10, 9, 10];

var Page_Input = panel1.add("group");
Page_Input.orientation = "row";
Page_Input.alignChildren = ["center", "center"];
Page_Input.spacing = 10;
Page_Input.margins = 6;

var edittext1 = Page_Input.add('edittext', undefined, undefined, {name: "edittext1"});
edittext1.helpTip = "Enter the page number where you want the search to start";
edittext1.preferredSize.width = 45;
edittext1.preferredSize.height = 23;

var statictext1 = Page_Input.add("statictext", undefined, "Thru");
statictext1.preferredSize.width = 52;
statictext1.preferredSize.height = 17;
statictext1.justify = "center";

var edittext2 = Page_Input.add('edittext', undefined, undefined, {name: "edittext2"});
edittext2.helpTip = "Enter the page number where you want the search to end";
edittext2.preferredSize.width = 45;
edittext2.preferredSize.height = 23;

var group2 = Widows_Report.add("group");
group2.orientation = "column";
group2.alignChildren = ["left", "center"];
group2.spacing = 10;
group2.margins = 1;

var group3 = group2.add("group");
group3.orientation = "row";
group3.alignChildren = ["center", "top"];
group3.spacing = 10;
group3.margins = 0;

var button1 = group3.add("button", undefined, "Start");
button1.preferredSize.width = 68;

var button2 = group3.add("button", undefined, "Close");
button2.preferredSize.width = 61;

var group4 = group2.add("group");
group4.orientation = "column";
group4.alignChildren = ["center", "bottom"];
group4.spacing = 12;
group4.margins = 5;

// Start Button Click Event
button1.onClick = function() {
    var startPage = parseInt(edittext1.text);
    var endPage = parseInt(edittext2.text);

    // Validate page numbers
    if (isNaN(startPage) || isNaN(endPage) || startPage < 1 || startPage > app.activeDocument.pages.length || endPage < 1 || endPage > app.activeDocument.pages.length || startPage > endPage) {
        alert("Invalid page numbers. Please enter valid page numbers.");
    } else {
        var reportWidow = "HERE ARE YOUR RESULTS:\nThese pages have widows\n\n_______________________\n\n";         
                                              
        for (var i = startPage - 1; i < endPage; i++) {
            var page = app.activeDocument.pages[i];
            var textFrames = page.textFrames;
            for (var j = 0; j < textFrames.length; j++) {
                var textFrame = textFrames[j];
                var paragraphs = textFrame.paragraphs;
                for (var k = 0; k < paragraphs.length; k++) {
                    var paragraph = paragraphs[k];
                    var fontSize = paragraph.pointSize;
                    if (fontSize >= 9.5 && fontSize <= 11) {
                        var lastLine = paragraph.lines[-1];
                        if (lastLine && lastLine.words.length === 1) {
                            reportWidow += "PAGE " + (i + 1) + ",     PARAGRAPH " + (k + 1) + "\r";
                                reportWidow += lastLine.words[0].contents + "\r\r";
                            }
                        }
                    }
                }
            }

        if (reportWidow !== "HERE ARE YOUR RESULTS:\n") {
            alert(reportWidow);
        } else {
           alert("Congratulations, No Widows Were Found!");
        }
    }
};

// Close Button Click Event
button2.onClick = function() {
    Widows_Report.close();
};

Widows_Report.show();

我需要运行脚本,找到任何widows(最后一行只有一个单词的文本段落。),然后在原始脚本窗口内生成搜索结果(而不是现在的第二个警报窗口) )。搜索结果是正确的,但我需要能够在 inDesign 文档中进行更正时查看结果(widows 列表)。

2个主要问题:

1 - 脚本窗口格式 - 我不知道如何使脚本窗口独立,以便我仍然可以在 inDesign 中工作同时查看搜索结果。有时结果是一长串,我需要在关闭窗口之前显示结果。

2 - 脚本搜索结果 - 现在,脚本将运行并正确找到 widows,问题是,脚本会生成第二个警报窗口,其中包含搜索结果。生成的信息是正确的,但我需要它显示在原始脚本窗口(首选)中,或者代替警报窗口,在新的独立窗口中显示搜索结果,该窗口在进行更正时将保持打开状态。

这是现在出现的搜索结果的截图:

Current Search Results Alert Window

我浏览了这个网站、网络,甚至向聊天 GPT 寻求帮助。我承认我对 inDesign 脚本很陌生,所以这两个问题对大多数人来说可能是基本问题。

javascript window adobe-indesign extendscript palette
1个回答
0
投票

这是快速简单的解决方案。它将最终消息保存为文本文件并打开它(可能是在 Windows 上的记事本或 macOS 上的 TextEdit 应用程序中)而不是警报窗口。

更改线路:

alert(reportWidow);

与:

report(reportWidow);

并在代码末尾添加函数:

function report(text) {
    var report_file = File(Folder.temp + '/widows.txt');
    report_file.encoding = 'utf-8';
    report_file.open('w');
    report_file.write(text);
    report_file.execute();
    report_file.close();
}
© www.soinside.com 2019 - 2024. All rights reserved.