Last active
December 18, 2019 15:55
-
-
Save rupertdev/c88e63aa716466c396aabf7ce769448c to your computer and use it in GitHub Desktop.
Iterm2 Python Script to match MacOS System Theme
This file contains 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 | |
# To Use: In iterm2, select Manage -> New Python Script, Basic script, daemon mode. Install python runtime if necessary and then paste in script, replace my themes with your chosen light and dark themes, save. In Scripts, uncheck and recheck your new script. | |
import asyncio | |
import iterm2 | |
from subprocess import run | |
from time import sleep | |
async def main(connection): | |
while True: | |
# Block until theme changes | |
p = run(['defaults', 'read', '-g', 'AppleInterfaceStyle']) | |
# Themes have space-delimited attributes, one of which will be light or dark. | |
if p.returncode == 0: | |
preset = await iterm2.ColorPreset.async_get(connection, "Night Owl") | |
else: | |
preset = await iterm2.ColorPreset.async_get(connection, "Solarized Light") | |
# Update the list of all profiles and iterate over them. | |
profiles = await iterm2.PartialProfile.async_query(connection) | |
for partial in profiles: | |
# Fetch the full profile and then set the color preset in it. | |
profile = await partial.async_get_full_profile() | |
await profile.async_set_color_preset(preset) | |
sleep(1) | |
iterm2.run_forever(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment