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

时间:2017-12-08 12:29:54

标签: terminal applescript macos-high-sierra

正如标题所说,我有一个苹果脚本:

in tab 2 of front window

过去工作正常,但自从High Sierra升级回归:

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

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

2 个答案:

答案 0 :(得分:3)

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

所以,之前,如果在一个窗口中打开了三个标签,我们可以将它们称为标签1 标签2 标签3 窗口1的 。现在,我们有窗口1 标签1 窗口2的标签1 标签1 窗口3的

我发现定位特定标签的最方便,最可靠的方法是识别包含具有 tty的标签对象的窗口对象属性值。我使用的命令看起来像这样:

    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

答案 1 :(得分:2)

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