选择取决于内容使用AppleScript和最佳做法终端特定的标签 [英] Select a particular tab in terminal depending upon the content using applescript and best practices

查看:304
本文介绍了选择取决于内容使用AppleScript和最佳做法终端特定的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个应用程序特定的问题。我试图找到并选择在Terminal.app取决于内内容的标签。下面是我在做什么:

This is an application specific problem. I am trying to find and select a tab in Terminal.app depending on contents within. Here is what I'm doing:

tell application "Terminal"
    set foundTabs to (every tab of every window) whose contents contains "selectme"
    repeat with possibleTab in foundTabs
        try
            set selected of possibleTab to true
        end try
    end repeat
end tell

如预期,是pretty万无一失这不是演戏。我不知道是否有人能提出一个方法用少得多的code要做到这一点(例如,在循环应该不是真的是必要的,但AppleScript的是一个难以捉摸的语言)。

This isn't acting as expected and is pretty foolproof. I wonder if someone can suggest a way to do this with much less code (for instance, the looping shouldn't really be necessary, but applescript is an elusive language).

感谢

推荐答案

事情是,下面的AppleScript会做你想要什么,但除非你的selectme​​字符串是非常独特的,你会发现它在许多标签。
但无论如何,在这里你去:

Thing is, the following Applescript will do what you want, but unless your "selectme" string is very unique, you will find it in many tabs. But anyway, here you go:

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 contents of tab j of window i contains "selectme" 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

这篇关于选择取决于内容使用AppleScript和最佳做法终端特定的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆