Skip to content

Instantly share code, notes, and snippets.

@gnachman
Created April 18, 2019 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnachman/2b31bbed2995f18ae9307339584db3ec to your computer and use it in GitHub Desktop.
Save gnachman/2b31bbed2995f18ae9307339584db3ec to your computer and use it in GitHub Desktop.
Prompt to enter tab title after creating a new tab
#!/usr/bin/env python3.7
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
def get_all_tab_ids():
result = []
for window in app.terminal_windows:
for tab in window.tabs:
result.append(tab.tab_id)
return set(result)
async with iterm2.NewSessionMonitor(connection) as mon:
before = get_all_tab_ids()
while True:
session_id = await mon.async_get()
after = get_all_tab_ids()
diff = after.difference(before)
for tab_id in diff:
tab = app.get_tab_by_id(tab_id)
if tab is None:
continue
await tab.async_select(True)
await iterm2.MainMenu.async_select_menu_item(connection, "Edit Tab Title")
before = after
iterm2.run_forever(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment