commit 81920d8e2b09c80b9cdd7353227f7eb4ce4fe4f0 parent 5dfe6d34f723c4ab741845aee366d3ccad600cb3 Author: Alex Balgavy <a.balgavy@gmail.com> Date: Thu, 1 Aug 2019 18:17:55 +0200 iterm2: python script to switch default profile New scripting additions are here woooo Former-commit-id: d1a208f31e352775c2ffb62e28280671f1cc7148 Diffstat:
A | iterm2/scripts/toggle_dark_mode.py | | | 21 | +++++++++++++++++++++ |
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/iterm2/scripts/toggle_dark_mode.py b/iterm2/scripts/toggle_dark_mode.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3.7 + +import iterm2 +from sys import argv + +async def main(connection): + profiles = [p for p in await iterm2.PartialProfile.async_query(connection) if p.name.startswith("Default ")] + if len(argv) > 1: + is_dark_theme = str(argv[1]) + else: + import subprocess + result = subprocess.run(['osascript', '-e', 'tell application "System Events" to tell appearance preferences to return (get dark mode as text)'], stdout=subprocess.PIPE) + is_dark_theme = str(result.stdout.rstrip().decode("utf-8")) + + for p in profiles: + if "Light" in p.name and is_dark_theme == "false": + await p.async_make_default() + elif "Dark" in p.name and is_dark_theme == "true": + await p.async_make_default() + +iterm2.run_until_complete(main)