How to select a tab in iTerm2 via AppleScript

Yep, I could find online a way to do it. Perhaps there is a better solution, but this works perfectly for me.

tell current window
        set foundProfile to false
       repeat with aTab in tabs
            set profName to profile name of current session of aTab
            if profName is "XXXXX" then
                select aTab
                set foundProfile to true
                exit repeat
            end if
        end repeat
        if not foundProfile then
            create tab with profile "XXXXX"
        end if