在前窗口的选项卡 2 中返回终端出现错误:无法获取窗口 1 的选项卡 2。(-1728) 自 High Sierra 更新以来

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

正如标题所说,我有一个 Apple Script 可以:

in tab 2 of front window

...过去工作正常但自从 High Sierra 升级返回后:

Terminal got an error: Can’t get tab 2 of window 1. (-1728)

对应于

errAENoSuchObject
我找不到任何关于此更改的文档 - 这是一个错误吗?有没有新的或更好的方法来做到这一点?

terminal applescript macos-high-sierra
2个回答
7
投票

对象层次结构略有变化。每个选项卡在 AppleScript 中被引用为 tab 1 属于唯一的父 window 对象。

所以,以前,如果在一个窗口中打开了三个选项卡,我们可以将它们称为tab 1tab 2tab 3 of window 1。现在,我们有window 1tab 1window 2tab 1,以及window 3tab 1

我发现针对特定选项卡的最方便可靠的方法是识别包含具有特定 tty 属性值的 tab 对象的 window 对象。我使用的命令看起来像这样:

    tell application "Terminal"
        get the id of the first window ¬
            whose first tab's tty contains "003"

        set w to result
        close window id w
    end tell

如果您想更清楚地了解事物,请运行:

    tell application “Terminal” to ¬
        get every tab of every window

还有这个:

    tell application “Terminal” to ¬
        get properties of every window

还有这个:

    tell application “Terminal” to ¬
        get properties of tab 1 of every window

4
投票

如果您的脚本的目的是打开选项卡并在每个选项卡中运行脚本,而不是在特定选项卡之间导航,您可以轻松修改脚本以在打开新选项卡后执行脚本

in selected tab of front window
,因为新选项卡始终自动选择。这是我修改后的脚本:

tell application "Terminal"
    activate
    do script "YOUR SCRIPT 1" in tab 1 of front window
    my makeTab()
    do script "YOUR SCRIPT 2" in selected tab of front window
    my makeTab()
    do script "YOUR SCRIPT 3" in selected tab of front window
end tell

on makeTab()
    tell application "System Events" to keystroke "t" using {command down}
    delay 0.2
end makeTab
© www.soinside.com 2019 - 2024. All rights reserved.