Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTerm2 & Atom - Switch profiles based on input bash commands in ~/.bash_profile, looking for suggestions

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!

like image 603
Felipe Avatar asked Nov 28 '25 03:11

Felipe


1 Answers

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()
like image 57
njha Avatar answered Nov 29 '25 19:11

njha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!