Last Updated: October 04, 2020
·
11.33K
· erasmospunk

Change iTerm2 color profile from the CLI

Have you ever worked with iTerm2 late in the evening with some dark colored tabs and the next morning you don't want to reopen them all with a different profile?

It turns out that iTerm2 can detect a printed special sequence and change the color profiles. To do it, simply put the following in you .bashrc or .zshrc (or any other shell you happen to use)

# Change iterm2 profile. Usage it2prof ProfileName (case sensitive)
it2prof() { echo -e "\033]50;SetProfile=$1\a" }

You're done! Just open a new tab and type it2prof DarkProfile or it2prof SomeOtherProfileName

Enjoy!

Related protips:

Use ⌥ ← and ⌥→ to jump forwards / backwards words in iTerm 2, on OS X

5 Responses
Add your response

It really helps!

over 1 year ago ·

thanks this is amazing

over 1 year ago ·

helps to also re-export ITERM_PROFILE if you're using it in anything else, i.e. vim to set a colorscheme there.

over 1 year ago ·

Does this still work for iTerm 3.0? When just calling echo -e "\033]50;SetProfile=PROFILE_NAME\a" from the command line, where PROFILE_NAME is one of the names listed under Preferences > Colors > Color Presets..., it echoes a blank line but does not change the profile. I've tried everything from copying the name verbatim to replacing spaces with dashes or underscores to no avail.

over 1 year ago ·

W.R.T my previous question, I made the foolish mistake of conflating iTerm color schemes with profiles. Once I made new profile with a different color scheme, this worked.

over 1 year ago ·