Skip to content

Instantly share code, notes, and snippets.

@dedy-purwanto
Created April 26, 2014 05:00
Show Gist options
  • Save dedy-purwanto/11312110 to your computer and use it in GitHub Desktop.
Save dedy-purwanto/11312110 to your computer and use it in GitHub Desktop.
Bulk remove iTerm2 color schemes.
# There was a day where I have too many color schemes in iTerm2 and I want to remove them all.
# iTerm2 doesn't have "bulk remove" and it was literally painful to delete them one-by-one.
# iTerm2 save it's preference in ~/Library/Preferences/com.googlecode.iterm2.plist in a binary format
# What you need to do is basically copy that somewhere, convert to xml and remove color schemes in the xml files.
$ cd /tmp/
$ cp ~/Library/Preferences/com.googlecode.iterm2.plist .
$ plutil -convert xml1 com.googlecode.iterm2.plist
$ vi com.googlecode.iterm2.plist
# Now remove the color schemes in the <key> and <dict> tags,
# to make it easier, record a macro in vi to remove the key (e.g: Desert/Solarized) using `dd`,
# and then remove its color dict with `dat` (delete around tag), and repeat the macro until
# all color schemes you want to delete is gone.
# Save the file, and copy it back:
$ cp com.googlecode.iterm2.plist ~/Library/Preferences/
# Note that iTerm2 has 'fallback' configuration in case something is wrong,
# You might want to remove them as well:
$ rm ~/Library/Preferences/iTerm2.plist
$ rm ~/Library/Preferences/net.sourceforge.iTerm.plist
# Now reload the configuration
$ cd ~/Library/Preferences/
$ defaults read com.googlecode.iterm2
# Restart iTerm, and check the color-scheme list in the Preferences menu, you shouldn't see the old color-schemes now.
@colepeters
Copy link

Super helpful. Thanks!

@asethwright
Copy link

You are awesome. Thanks for sharing.

@fresham
Copy link

fresham commented Apr 16, 2015

πŸ‘ Thanks for sharing

@jjuarez
Copy link

jjuarez commented Oct 27, 2015

Thanks for sharing this trick

@kepingwang
Copy link

Great. Thank you!

@benweatherman
Copy link

Saved a bunch of time, thank you!

@Akatsukishen
Copy link

Big thx.

@zazazack
Copy link

zazazack commented Feb 9, 2017

This isn't necessarily easier, but as an alternative for those who prefer to use GUI: Open the plist file with Xcode and use the plist editor to delete the desired key/value pairs under the 'Color Custom Presets' property.

@shunhuahan
Copy link

thanks a lot!

@dx7
Copy link

dx7 commented May 10, 2017

πŸ‘

@AdrienGiboire
Copy link

Thanks!

@yangshiqi
Copy link

nice, 3q.

@amaurycatelan
Copy link

Yep, Very useful! πŸ‘

@malikbenkirane
Copy link

very useful πŸ‘

@anubhavcodes
Copy link

anubhavcodes commented Jan 16, 2018

Thank you. Saved a lot of my time.

@StevenXL
Copy link

StevenXL commented Jul 8, 2018

This was exactly what I needed. Thank you.

@eproxus
Copy link

eproxus commented Apr 3, 2019

If you have Xcode installed you can edit the file directly. When iTerm2 is closed, run the following in Terminal.app:

$ open ~/Library/Preferences/com.googlecode.iterm2.plist

Then you get a nice GUI editor. Remove any desired color settings under the key Custom Color Presets, save the file and restart iTerm.

@mzcabc
Copy link

mzcabc commented Apr 3, 2019

If you have Xcode installed you can edit the file directly. When iTerm2 is closed, run the following in Terminal.app:

$ open ~/Library/Preferences/com.googlecode.iterm2.plist

Then you get a nice GUI editor. Remove any desired color settings under the key Custom Color Presets, save the file and restart iTerm.

very useful

@raghavkarol
Copy link

Works great! thanks for sharing

@seth-macpherson
Copy link

Fantastic! Thank you!

@irfanbaigse
Copy link

Works like charm $ open ~/Library/Preferences/com.googlecode.iterm2.plist

@domabbott92
Copy link

πŸ‘

@ewal
Copy link

ewal commented Feb 14, 2020

πŸ‘

@rockyzhang24
Copy link

rockyzhang24 commented Apr 7, 2020

Save my life!! This is awesome! πŸ₯³

@tgy
Copy link

tgy commented Apr 17, 2020

Modified self-contained version that does everything for the lazy

#!/usr/bin/env bash
# There was a day where I have too many color schemes in iTerm2 and I want to remove them all.
# iTerm2 doesn't have "bulk remove" and it was literally painful to delete them one-by-one.

# iTerm2 save it's preference in ~/Library/Preferences/com.googlecode.iterm2.plist in a binary format
# What you need to do is basically copy that somewhere, convert to xml and remove color schemes in the xml files.

cd /tmp/
cp ~/Library/Preferences/com.googlecode.iterm2.plist .
plutil -convert xml1 com.googlecode.iterm2.plist

# Now remove the color schemes in the <key> and <dict> tags,
# to make it easier, record a macro in vi to remove the key (e.g: Desert/Solarized) using `dd`,
# and then remove its color dict with `dat` (delete around tag), and repeat the macro until
# all color schemes you want to delete is gone.

# backup the plist file just in case
cp com.googlecode.iterm2.plist com.googlecode.iterm2.plist.bkp

# remove the tags
python - << EOF
#!/usr/bin/env python3
import xml.etree.ElementTree as et
path = "com.googlecode.iterm2.plist"
tree = et.parse(path)
root = tree.getroot()
dict_element = root.find("dict")
found_custom_color_presets = False
for child in dict_element:
    if found_custom_color_presets:
        dict_element = child
        break
    elif child.tag == "key" and child.text == "Custom Color Presets":
        found_custom_color_presets = True
to_remove = list()
next_is_dict_to_remove = False
for child in dict_element:
    if next_is_dict_to_remove:
        to_remove.append(child)
        next_is_dict_to_remove = False
    elif child.tag == "key" and child.text.startswith("base16"):
        to_remove.append(child)
        next_is_dict_to_remove = True
for child in to_remove:
    dict_element.remove(child)
with open("com.googlecode.iterm2.plist", "w") as f:
    f.write(et.tostring(root).decode())

EOF

cp com.googlecode.iterm2.plist ~/Library/Preferences/

# Note that iTerm2 has 'fallback' configuration in case something is wrong,
# You might want to remove them as well:

rm -f ~/Library/Preferences/iTerm2.plist
rm -f ~/Library/Preferences/net.sourceforge.iTerm.plist

# Now reload the configuration

cd ~/Library/Preferences/
defaults read com.googlecode.iterm2

# Restart iTerm, and check the color-scheme list in the Preferences menu, you shouldn't see the old color-schemes now.

@ruolis
Copy link

ruolis commented Sep 4, 2020

πŸ‘

@sbatial
Copy link

sbatial commented Sep 16, 2020

Thanks 🀝

@tommg
Copy link

tommg commented Nov 6, 2020

Thanks very much this was super useful πŸ™

@vantoo
Copy link

vantoo commented Sep 20, 2022

牛逼

@dmj111
Copy link

dmj111 commented Apr 16, 2023

πŸ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment