Skip to content

Instantly share code, notes, and snippets.

@MSylvia
Created June 14, 2014 14:29
Show Gist options
  • Save MSylvia/4e90860743f1a4de187d to your computer and use it in GitHub Desktop.
Save MSylvia/4e90860743f1a4de187d to your computer and use it in GitHub Desktop.
Convert .itermcolors file to html hex
#!/usr/bin/env python
#
# Convert .itermcolors files to hex colors for html
import sys
import xml.etree.ElementTree as ET
def rgb_to_hex(rgb):
return '#%02x%02x%02x' % rgb
# MAIN
def main():
if len(sys.argv) < 2:
print "usage: ./convert_itermcolors.py file.itermcolors"
exit()
tree = ET.parse(sys.argv[1])
root = tree.getroot()
keys = root.findall("./dict/key")
dicts = root.findall("./dict/dict")
for i in range(len(keys)):
b = int( float( dicts[i][1].text) * 255.0)
g = int( float( dicts[i][3].text) * 255.0)
r = int( float( dicts[i][5].text) * 255.0)
print rgb_to_hex((r,g,b)) + " //" + keys[i].text
if __name__ == '__main__':
main()
» ./convert_itermcolors.py test.itermcolors
#2b303b //Ansi 0 Color
#bf616a //Ansi 1 Color
#343d46 //Ansi 10 Color
#4f5b66 //Ansi 11 Color
#a7adba //Ansi 12 Color
#dfe1e8 //Ansi 13 Color
#ab7967 //Ansi 14 Color
#eff1f5 //Ansi 15 Color
#a3be8c //Ansi 2 Color
#ebcb8b //Ansi 3 Color
#8fa1b3 //Ansi 4 Color
#b48ead //Ansi 5 Color
#96b5b4 //Ansi 6 Color
#c0c5ce //Ansi 7 Color
#65737e //Ansi 8 Color
#d08770 //Ansi 9 Color
#2b303b //Background Color
#c0c5ce //Bold Color
#c0c5ce //Cursor Color
#2b303b //Cursor Text Color
#c0c5ce //Foreground Color
#c0c5ce //Selected Text Color
#4f5b66 //Selection Color
@pdarragh
Copy link

This was useful to me, thank you! I created an updated version that uses Python 3 and the plistlib module here: https://gist.github.com/pdarragh/14549bbf4d1a2391b8672bcdf93ced8f.

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