【问题标题】:Can't retrieve custom title of OSX terminal tabs无法检索 OSX 终端选项卡的自定义标题
【发布时间】:2013-07-22 12:19:47
【问题描述】:

我正在尝试在 OSX 中选择某个终端选项卡并向其发送击键。但是 OSX 10.8.4 中的终端似乎没有为选项卡的自定义标题存储“终端”以外的任何内容,即使您使用检查器设置了自定义标题也是如此。有任何想法吗?这是我想用来选择正确选项卡的代码:

tell application "Terminal"
  set allWindows to number of windows

  repeat with i from 1 to allWindows
    set allTabs to number of tabs of window i
    repeat with j from 1 to allTabs
      if custom title of tab j of window i contains "blah" then
        set frontmost of window i to true
        set selected of tab j of window i to true
      end if
    end repeat
  end repeat
end tell 

【问题讨论】:

    标签: macos terminal applescript


    【解决方案1】:

    我正在使用旧版本的 OSX,所以我无法复制您的问题(您的代码对我来说很好),但也许可以尝试:

    if ((custom title of (current settings of (tab j of (window i)))) as string) contains "blah" then
    

    【讨论】:

    • @CarlYoungblood 啊,在这种情况下,我建议您查看 AppleScript 库,看看是否能找到正确的语法。
    【解决方案2】:

    确保您以这种方式设置选项卡名称:

    tell "application" "Terminal"
    # ...
      set the_tab to tab 1 of the front window -- replace with your tab selector
      tell settings set "Basic"
          set custom title of the_tab to "My Tab Name"
      end tell
    # ...
    end tell
    

    您应该能够检索标签名称:

    tell "application" "Terminal"
         set the_name to custom title of the_tab as string
    end tell
    

    在 OSX 10.8.4 上为我工作

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 2022-07-26
      • 1970-01-01
      • 2015-04-07
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      相关资源
      最近更新 更多