如何通过脚本显示和隐藏标准 InDesign 面板?

How to show and hide standard InDesign panels through scripting?

例如,我可以获得对“脚本”面板的引用;但它似乎没有像通过脚本创建面板那样的 showhide 方法(请参见下面的代码)。如何在不调用相应菜单项的情况下以编程方式显示或隐藏它?

function findPanelByName(name) { // String → Panel|null
    for (var iPanel = 0; iPanel < app.panels.length; iPanel++) {
        var panel = app.panels[iPanel];
        if (panel.name == name) {
            return panel;
        }
    }
    return null;
}

var scriptsPanel = findPanelByName('Scripts');

scriptsPanel.show(); // → “scriptsPanel.show is not a function”

一些事情:您获得正确面板的方法不必要地复杂。您可以像这样使用面板集合的 item 方法来获取面板:

var scriptsPanel = app.panels.item('Scripts');

那么,您就不需要使用show()来显示面板(因为该方法不存在),但您可以通过设置它的visible 属性 为真:

scriptsPanel.visible = true;

最后,如果其他人要使用该脚本,您应该确保它也适用于国际版本的 InDesign。在我的德语版本中,上面的面板示例将不存在,因为它被命名为 Skripte 而不是 Scripts。为避免这种情况,您可以使用 InDesign 的语言独立键:

var scriptsPanel = app.panels.item('$ID/Scripting');

所以,总而言之,整个脚本可以缩短到这一行

app.panels.item('$ID/Scripting').visible = true;