My fork of https://gist.github.com/jamesmacfie/2061023e5365e8b6bfbbc20792ac90f8 , adapted to also switch Emacs.
How to use
Copy the Python script to the following location:
$HOME/Library/Application Support/iTerm2/Scripts/AutoLaunch/
Create the directory if it doesn't exist. Reboot iTerm2, and say "Yes" if it asks you to download a Python runtime.
Emacs
This will automatically update Emacs themes, as well, through emacsclient. Make
sure you have Emacs running as a server in your init.el ((server-start)
).
If Emacs isn't running, this script will skip it silently, no problem. But the emacsclient binary must exist.
For context, here's what I use for my init.el:
;; Start emacs in server mode, unless there already is one
(when (and (require 'server nil :noerror)
(not (server-running-p)))
(server-start))
(defun hly/disable-themes ()
(mapc 'disable-theme custom-enabled-themes))
(defun hly/light-mode ()
(interactive)
;; I like the default theme.
(hly/disable-themes))
(defun hly/dark-mode ()
(interactive)
(hly/disable-themes)
(load-theme 'tango-dark))
Changing what themes this uses
Note the constants at the top of the file. These are iTerm2 colour profiles, and Emacs functions (which you must define in your Emacs config) to actually switch the theme.
I appreciate the iTerm script refactoring in this!👌 🙏