在前窗口返回终端的标签2中,终端有一个错误:由于高塞拉更新,因此无法获得窗口1的选项卡2(-1728)



标题所说的我有一个Apple脚本,可以:

in tab 2 of front window

...曾经工作正常,但由于山脉升级高返回:

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

对应于errAENoSuchObject

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

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

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

我找到了针对特定选项卡的最方便,最可靠的方法是识别包含带有特定 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

如果您的脚本的目的是打开选项卡并在每个脚本中运行一个脚本,而不是在特定选项卡之间导航,则可以在打开新选项卡之后轻松修改脚本以执行脚本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

最新更新