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

[亡魂溺海] 提交于 2019-12-07 11:50:43

问题


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

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


回答1:


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


来源:https://stackoverflow.com/questions/5047748/select-a-particular-tab-in-terminal-depending-upon-the-content-using-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!