iterm_toggle_dark_profile.py (908B)
1 #!/usr/bin/env python3 2 3 import iterm2 4 from sys import argv 5 6 async def main(connection): 7 profiles = [p for p in await iterm2.PartialProfile.async_query(connection) if p.name.startswith("Default ")] 8 if len(argv) > 1: 9 is_dark_theme = str(argv[1]) 10 else: 11 import subprocess 12 result = subprocess.run(['osascript', '-e', 'tell application "System Events" to tell appearance preferences to return (get dark mode as text)'], stdout=subprocess.PIPE) 13 is_dark_theme = str(result.stdout.rstrip().decode("utf-8")) 14 15 for p in profiles: 16 if "Light" in p.name and is_dark_theme == "false": 17 await p.async_make_default() 18 return 19 elif "Dark" in p.name and is_dark_theme == "true": 20 await p.async_make_default() 21 return 22 try: 23 iterm2.run_until_complete(main) 24 except Exception as exception: 25 print("Error: ", exception)