Change iTerm2 Default profile preset with “defaults write…”

itermscript

I want to do this in my dotfiles script.

I managed to download the preset I want using curl and open it, but I don't know how to set it in the default profile:

curl -L https://raw.githubusercontent.com/chriskempson/base16-iterm2/master/base16-ocean.dark.itermcolors > /tmp/base16-ocean.dark.itermcolors
open /tmp/base16-ocean.dark.itermcolors

I tried AppleScript, but I never used it, and it seemed to be too much work for little… I believe it could be a simpler way, using defaults write, for example.

Any ideas?

Best Answer

To expand on the existing answer, if you load the colours you'd like once then you can export your preferences list file from the 'General' tab to a location in your dotfiles.

Thus, in my setup script, I have:

defaults write com.googlecode.iterm2 "PrefsCustomFolder" -string "/Users/ojf/dotfiles/iterm"
defaults write com.googlecode.iterm2 "LoadPrefsFromCustomFolder" -bool true

As long as your custom folder plist also says to load from the same custom folder (!) you'll be fine.