Created
November 27, 2022 19:41
-
-
Save a5ync/1ec69cb5e814c498a1b3eaa09a452bcf to your computer and use it in GitHub Desktop.
iTerm2 automate tab creation
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 | |
# This script was created with the "basic" environment which does not support adding dependencies | |
# with pip. | |
async def main(connection): | |
# Your code goes here. Here's a bit of example code that adds a tab to the current window: | |
app = await iterm2.async_get_app(connection) | |
window = app.current_terminal_window | |
if window is not None: | |
tab = await window.async_create_tab() | |
await tab.async_set_title('something new') | |
session1 = tab.current_session | |
session2 = await session1.async_split_pane(vertical=False) | |
await session1.async_send_text('vi\n') | |
change = iterm2.LocalWriteOnlyProfile() | |
color = iterm2.Color(255, 128, 128) | |
change.set_tab_color(color) | |
change.set_use_tab_color(True) | |
for s in tab.sessions: | |
await s.async_set_profile_properties(change) | |
else: | |
# You can view this message in the script console. | |
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