开发者

Select a particular tab in terminal depending upon the content using applescript and best practices

开发者 https://www.devze.com 2023-02-11 04:32 出处:网络
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:

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开发者_JS百科 selected of possibleTab to true
        end try
    end repeat
end tell

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).

Thanks


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
0

精彩评论

暂无评论...
验证码 换一张
取 消