Skip to content

Instantly share code, notes, and snippets.

@dustinrouillard
Last active July 14, 2020 04:40
Show Gist options
  • Save dustinrouillard/53a243415672558683df9259b32394db to your computer and use it in GitHub Desktop.
Save dustinrouillard/53a243415672558683df9259b32394db to your computer and use it in GitHub Desktop.
This python script will make iTerm with your macOS theme. (Requires a Profile called Light and Dark)
#!/usr/bin/env python3
import asyncio
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
effectiveTheme = await app.async_get_variable("effectiveTheme")
parts = effectiveTheme.split(" ")
if "dark" in parts:
preset = 'Dark'
else:
preset = 'Light'
profiles=await iterm2.PartialProfile.async_query(connection)
for partial in profiles:
full = await partial.async_get_full_profile()
if partial.name == preset:
await partial.async_make_default()
for window in app.terminal_windows:
for tab in window.tabs:
for session in tab.sessions:
await session.async_set_profile(full)
async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP, "effectiveTheme", None) as mon:
while True:
theme = await mon.async_get()
parts = theme.split(" ")
if "dark" in parts:
preset = 'Dark'
else:
preset = 'Light'
app = await iterm2.async_get_app(connection)
profiles=await iterm2.PartialProfile.async_query(connection)
for partial in profiles:
full = await partial.async_get_full_profile()
if partial.name == preset:
await partial.async_make_default()
for window in app.terminal_windows:
for tab in window.tabs:
for session in tab.sessions:
await session.async_set_profile(full)
iterm2.run_forever(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment