I'm trying to write an AppleScript for iTerm2 that for a fixed profile ("session"?) name, let's say "Dev Server", checks whether there is a tab with that profile in any window (or just the current window if that's easier). If any such tab exists, I'd like to activate ("select") it. If there's multiple tabs with the same session, the selecting any one of them is fine. If there is no tab with that session name, I'd like to create a new tab in the current window with that name.
1 Answer
I figured it out:
tell application "iTerm"
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 "Dev Server" then
select aTab
set foundProfile to true
exit repeat
end if
end repeat
if not foundProfile then
create tab with profile "Dev Server"
end if
end tell
end tell