TIL: hotkeys for iTerm2 tabs past 9

I keep more than 10 tabs open in iTerm2, but it only binds ⌘1–⌘9 to tabs — and ⌘9 jumps to the last tab, not the 9th. There’s no built-in “select tab N” action for tab 10 and beyond.

The fix is iTerm2’s Python API. A tiny daemon registers a select_tab(index) function that activates the Nth tab of the current window:

# ~/Library/Application Support/iTerm2/Scripts/AutoLaunch/select_tab.py
import iterm2

async def main(connection):
    app = await iterm2.async_get_app(connection)

    @iterm2.RPC
    async def select_tab(index):
        window = app.current_terminal_window
        if window and 0 <= index < len(window.tabs):
            await window.tabs[index].async_activate()

    await select_tab.async_register(connection)

iterm2.run_forever(main)

Turn it on under Settings → General → Magic → Enable Python API, drop the file in AutoLaunch/, and restart iTerm2 (or run it once from the Scripts menu).

Then bind keys in Settings → Keys → Key Bindings: action Invoke Script Function, with a call like select_tab(index: 9). The index is 0-based, so tab 10 is index: 9. My right-Cmd is a Hyper key (⌃⌥⇧⌘), so the second row is just “Hyper + number”:

⌘⌥⌃⇧1     → select_tab(index: 9)   # tab 10
⌘⌥⌃⇧2     → select_tab(index: 10)  # tab 11
…
⌘⌥⌃⇧0     → select_tab(index: 18)  # tab 19

I tried to remap ⌘9 to the real 9th tab too, but it doesn’t take: iTerm2’s built-in ⌘+number tab navigation is handled before the Key Bindings map, so a custom ⌘9 binding never fires — ⌘9 keeps jumping to the last tab. The only way around it is to move the whole built-in tab modifier off ⌘ and rebind ⌘1–⌘8 by hand, which isn’t worth it. So ⌘9 stays “last tab”, and the Hyper row picks up from tab 10. The Hyper combo (⌃⌥⇧⌘) also dodges ⌘⇧3/4/5, which macOS reserves for screenshots.


Let's stay connected!

If you like the post, subscribe to my newsletter to get latest updates:

Author

I'm Oliver Nguyen. A software maker working mostly in Go and JavaScript. I enjoy learning and seeing a better version of myself each day. Occasionally spin off new open source projects. Share knowledge and thoughts during my journey.