Select a specific tab in the terminal depending on the content using application and best practices

This is an application specific issue. I am trying to find and select a tab in Terminal.app depending on the contents inside. That's 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 does not work as expected, and is pretty reliable. I wonder if anyone can suggest a way to do this with much less code (for example, a loop doesn't have to be really necessary, but applescript is an elusive language).

thank

+3
source share
1 answer

, Applescript , , "selectme" , . , :

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
+2

Source: https://habr.com/ru/post/1793171/


All Articles