In iTerm2, in the menu bar go to Scripts > Manage > New Python Script
Select Basic. Select Long-Running Daemon
Give the script a decent name (I chose auto_dark_mode.py
)
Save and open the script in your editor of choice.
Copy and paste the script below and save
Go back to iTerm2, go to Scripts in the menu bar and select the script you just saved.
Try toggling Dark mode to see what happens! Reminder it's under Appearance in the System Settings
Note in the script below on lines 15 and 17 that we have a string that we're passing to iTerm2. Change these to whatever you like. The text is whatever appears in the dropdown in the iTerm2 settings under Profile/Color for when you'd want to change the theme manually.
After you change the script you'll have to stop and start the script if it's running already
@plivox good rewrite. Just a perfectionists nitpick: name it
AutoSwitchTheme
(typo)However, regardless which version I use (they basically all do the same), I have 2 problems (on Catalina).
async_set_color_preset
takes 2-3 seconds - and I have a couple of profiles (> 40), So when switching theme, the computer is blocked for over 2 minutes.