Skip to content

Instantly share code, notes, and snippets.

@joebui
Last active March 28, 2022 14:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joebui/977e90f2475955923612f3f9c134bec0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3.7
# Import iterm2 library
import iterm2
async def main(connection):
# Get current window
app = await iterm2.async_get_app(connection)
window = app.current_terminal_window
if window is not None:
# Create new tab, get session and print text
tab = await window.async_create_tab()
session = tab.current_session
# \n is crucial as it simulates Enter.
await session.async_send_text('echo "hello world from main pane"\n')
# Create new pane on the right and print text
pane2 = await session.async_split_pane(vertical=True)
await pane2.async_send_text('echo "hello world from pane 1"\n')
# Create new pane at the bottom of pane2 and print text
pane3 = await pane2.async_split_pane(vertical=False)
await pane3.async_send_text('echo "hello world from pane 2"\n')
# Create new pane at the bottom of main pane (session) and print text
pane4 = await session.async_split_pane(vertical=False)
await pane4.async_send_text('echo "hello world from pane 3"\n')
else:
print("No current window")
iterm2.run_until_complete(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment