3

The weather has gotten pretty decent where I am at and recently I've been working outside more often than not. Usually when inside I use a dark theme that is comfortable for the eye, but outside, obviously, I can't see crap and resort to changing iTerm & Atom themes' to ones with a light background.

I'm a man of shortcuts, and after doing some investigation online and some Googling I haven't seen anything that would allow me to change iTerm's or Atom's configuration directly via the terminal. The objective would be to type light to change my Atom's and iTerm's configuration to a lighter theme, and dark to change them back to dark (via ~/.bash_profile).

Regarding iTerm in specific, my idea was to directly modify the configuration file at ~/Library/Prferences/com.googlecode.iterm2.plist when the commands are run. More specifically (so I don't have to deal with converting .plist files to .xml and then back) I would just set up two git branches and flip between them on command.

However, the solution above is extremely bootleg, and not effectively transferable over to other machines, which I do like to be the cases I reformat my computer (yearly clean). I was wondering if someone would have an idea, or has encountered something similar to this and would be willing to give some suggestions that might possibly work.

Much appreciated!

felipe
  • 7,324
  • 2
  • 28
  • 37
  • https://coderwall.com/p/s-2_nw/change-iterm2-color-profile-from-the-cli for iterm2 for atom there's multiple configs you can use I think your preference will dictate which one you use though e.g. https://atom.io/packages/theme-switch / https://atom.io/packages/dark-mode / https://atom.io/packages/mojave-dark-mode etc. – bob dylan Nov 25 '19 at 12:26

1 Answers1

1

If you're on 10.14 or later (with system dark theme) you can have both of those applications sync with the system dark theme...

To make iTerm sync with system dark, follow these instructions. Basically make a Dark and Light profile in iTerm, and drop this in a bash profile. More details at that link if needed.

if [[ "$(uname -s)" == "Darwin" ]]; then
    sith() {
        val=$(defaults read -g AppleInterfaceStyle 2>/dev/null)
        if [[ $val == "Dark" ]]; then
            i
        fi
    }

    i() {
        if [[ $ITERM_PROFILE == "Terminal" ]]; then
            echo -ne "\033]50;SetProfile=Dark\a"
            export ITERM_PROFILE="Dark"
        else
            echo -ne "\033]50;SetProfile=Terminal\a"
            export ITERM_PROFILE="Terminal"
        fi
    }

    sith
fi

To make Atom sync with the system dark theme, use dark-mode or mojave-dark-mode.

Finally, you can easily toggle between light and dark mode either from Alfred with this plugin, an app called Shifty, or via /usr/bin/osascript with this command... (you can call it from a bash script and wire it up however you need).

systemEvents.appearancePreferences.darkMode = !systemEvents.appearancePreferences.darkMode()
njha
  • 1,118
  • 1
  • 13
  • 24
  • 1
    Oh man, I'm going to give this a try! I appreciate the post. If everything works as expected I'll go ahead and reward +50. Thank you! – felipe Nov 30 '19 at 23:01