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
Thanks for this. It didn't update my iTerm colors immediately, so I've created a version that updates all Sessions and Profiles.
I don't use Profiles much so my version makes all terminal sessions update immediately.
It also has a bit more error handling and documentation.
Hope it helps someone:
https://gist.github.com/doublethefish/c339b659738fdb652e820e3b40f97f36