Created
April 18, 2019 03:34
-
-
Save gnachman/2b31bbed2995f18ae9307339584db3ec to your computer and use it in GitHub Desktop.
Prompt to enter tab title after creating a new tab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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