iTerm2-Color-Schemes icon indicating copy to clipboard operation
iTerm2-Color-Schemes copied to clipboard

Automate installation of iTerm2 themes

Open pcgeek86 opened this issue 6 years ago • 12 comments

I love these themes, thank you for documenting and sharing them on GitHub. My MacBook was just reimaged this week, and I lost all the themes that I had [manually] installed before.

Right now, the installation directions don't contain any automated installation steps. It would be really awesome if I could simply do a git clone, and then run some script to install the themes.

I can help contribute this capability, if someone can describe the process to me. Let me know.

Cheers, Trevor Sullivan

pcgeek86 avatar Nov 15 '17 20:11 pcgeek86

Hi Trevor,

I don't know of any process. That doesn't mean there isn't one, I just don't know if it exists. If someone has any ideas, by all means, submit them and I'd be happy to include!

mbadolato avatar Nov 15 '17 23:11 mbadolato

Cool, I was hoping that maybe it would be as easy as copying the files into the right place, or editing a configuration file (plist, json, etc.). Maybe someone will chime in someday, either here, or using another medium! :) Thank you!

pcgeek86 avatar Nov 16 '17 00:11 pcgeek86

Well it's not just putting files in a location; they have to be imported. I don't know if there's a way to automatically trigger that

mbadolato avatar Nov 16 '17 02:11 mbadolato

Before you read the rest, 'no, I do not have a solution for this'. Question tickled my curiosity and did a bit of digging.

I was actually looking for themes for Microsoft's colortool and saw this issue here. On windows, it's simply colortool.exe -b <theme_name> to set it from command line.

On Mac, assuming Trevor is using iTerm2, I think to be able to do simulate import you would need to convert the theme info into a format that iTerm2 plist(~/Library/Preferences/com.googlecode.iterm2.plist) uses.

I did a dump of it in pristine form: default read ~/Library/Preferences/com.googlecode.iterm2.plist > /tmp/before

and compared it to what happens after I pick up a color theme (Belafonte Day.theme). default read ~/Library/Preferences/com.googlecode.iterm2.plist > /tmp/after

Here is what I saw: diff /tmp/before /tmp/after `> "Belafonte Day" = {

        "Ansi 0 Color" =             {
            "Blue Component" = "0.1058823529411765";
            "Green Component" = "0.06666666666666667";
            "Red Component" = "0.1254901960784314";
        };
        "Ansi 1 Color" =             {
            "Blue Component" = "0.05490196078431372";
            "Green Component" = "0.06274509803921569";
            "Red Component" = "0.7450980392156863";
        };
        "Ansi 10 Color" =             {
            "Blue Component" = "0.3843137254901961";
            "Green Component" = "0.5058823529411764";
            "Red Component" = "0.5215686274509804";
        };

.......< cut the rest, this is enough to make the point >

    };`

I went ahead and used python's plistlib to check the contents of that file as well. Here is how it looks:

`> g = plistlib.readPlist('/Users/adil/Library/Preferences/com.googlecode.iTerm2.plist')

pprint(g) {'AppleAntiAliasingThreshold': 1, 'AppleScrollAnimationEnabled': 0, 'AppleSmoothFixedFontsSizeThreshold': 1, 'AppleWindowTabbingMode': 'manual', 'Custom Color Presets': {'Belafonte Day': {'Ansi 0 Color': {'Blue Component': 0.10588235294117647, 'Green Component': 0.06666666666666667, 'Red Component': 0.12549019607843137}, 'Ansi 1 Color': {'Blue Component': 0.054901960784313725, 'Green Component': 0.06274509803921569, 'Red Component': 0.7450980392156863}, 'Ansi 10 Color': {'Blue Component': 0.3843137254901961, 'Green Component': 0.5058823529411764, 'Red Component': 0.5215686274509804}, 'Ansi 11 Color': {'Blue Component': 0.28627450980392155, 'Green Component': 0.6470588235294118, 'Red Component': 0.9176470588235294}, 'Ansi 12 Color': {'Blue Component': 0.4745098039215686, 'Green Component': 0.41568627450980394, 'Red Component': 0.25882352941176473}, ...

`

So, I guess import process is converting binary data, and even the names in .terminal file into values that are meaningful to iTerm2 (probably here somewhere: https://github.com/gnachman/iTerm2/blob/master/ColorPicker/ColorPicker/CPKColorNamer.m)

I maybe on the wrong path here, but thought I would share anyway.

AdilHindistan avatar Jan 24 '18 22:01 AdilHindistan

Interesting research! I'll be curious to hear if you get further! Thanks

mbadolato avatar Jan 25 '18 02:01 mbadolato

I am not sure if I am missing something: not spending too much time reading the question. But, in iterm2, where you import colorschemes, click on top scheme, and hold down shift, then click on bottom scheme, click open (import them)

before doing this, git clone this repo.

chuckplantain avatar Jan 31 '18 20:01 chuckplantain

@chuckplantain That works for importing all of the themes manually. The OP was asking about doing it automatically so that it could be scripted (i.e., new machine setup, etc)

mbadolato avatar Feb 01 '18 02:02 mbadolato

This is an old thread, but in case anyone's interested, this seems to work for me to do a scripted install of iTerm:

Bare Installs

  1. First, on an existing iTerm installation, get all your preferences dialed in the way you want them.
  2. Save a copy of the iTerm preferences file. This is a bit tricky, because it's cached in memory by the cfprefsd daemon, so the prefs file isn't always up to date. So: a. Quit iTerm. b. From the Terminal app: b. killall cfprefsd to kill the preferences caching daemon. From what I've seen, when you send it the kill signal, it writes its cache to disk before it dies. Don't worry about killing the daemon; the system will restart it as needed, usually within a few seconds. c.cp ~/Library/Preferences/com.googlecode.iterm2.plist ~/init/ or wherever you want to put it. In my case, ~/init is a subdir in my dotfiles repo.
  3. Now you have what you need to create a scripted install on your bare machine. The specific commands in my setup script (using Homebrew) are simply:
brew cask install iterm2
cp ~/init/com.googlecode.iterm2.plist ~/Library/Preferences

Note that the above steps will only work reliably on a bare machine, because until iTerm starts up, there is no existing preferences file in ~/Library/Preferences for cfprefsd to cache.

Existing Setups

If, like me, you use multiple Macs and want to propagate preferences that you've saved (above) to another machine, you can't simply copy the preferences file into place, because if iTerm is running, cfprefsd may overwrite your changes. So you have to:

  1. Quit iTerm
  2. From Terminal (not iTerm):
killall cfprefsd
cp ~/init/com.googlecode.iterm2.plist ~/Library/Preferences

Now, when you start iTerm again, it should pick up your new preferences.

careyjung avatar Jul 22 '18 17:07 careyjung

Hey folks, previously I'd copy and paste across my theme settings, now I use the included 'Solarized Dark' via (preferences > profiles > colors > color presets… :

screen shot 2018-10-15 at 11 01 22

With one additional setting being to the 'Minimum Contrast'.

I'm wondering if anyone has any idea how I could automate these 2 steps please?

s10wen avatar Oct 15 '18 10:10 s10wen

I came up with this pretty dirty hack here: mkdir iterm-colorschemes; cd iterm-colorschemes; curl -s 'https://iterm2colorschemes.com/' | grep href | grep -v 'created by' | grep itermcolor | cut -d'"' -f 2 | sort | while read line; do wget "$line"; done; for i in *.itermcolors; do open "$i"; done This opens a few hundred dialog windows - just keep your return key pressed for 15sec or so and you're fine. ;-)

ghost avatar Apr 03 '20 14:04 ghost

image

I have to admit this gets a bit congested, but hey, rainbows and unicorns I guess?

ghost avatar Apr 03 '20 15:04 ghost

Command below appears to do the trick without opening hundreds of terminal windows when you cd into the terminal directory.

for file in *.terminal; do defaults write com.apple.Terminal "Custom Color Presets" -dict-add "${file%.*}" "$(cat "$file")"; done

gusanmaz avatar Mar 01 '23 16:03 gusanmaz