Skip to content

Instantly share code, notes, and snippets.

@morinap
Created January 29, 2019 13:17
Show Gist options
  • Save morinap/240866f6ba1427c0a28385019105e4f2 to your computer and use it in GitHub Desktop.
Save morinap/240866f6ba1427c0a28385019105e4f2 to your computer and use it in GitHub Desktop.
Python Script to drop iTerm colors scheme over top of an Ansi Colors.plist File
#!/usr/local/bin/python
import sys
import plistlib
source_file = sys.argv[1]
dest_file = sys.argv[2]
source_dict = plistlib.readPlist(source_file)
dest_dict = plistlib.readPlist(dest_file)
color_number_map = {
0: 'black',
1: 'darkred',
2: 'darkgreen',
3: 'darkyellow',
4: 'darkblue',
5: 'darkmagenta',
6: 'darkcyan',
7: 'lightgray',
8: 'darkgray',
9: 'red',
10:'green',
11:'yellow',
12:'blue',
13:'magenta',
14:'cyan',
15:'white',
}
for key, value in color_number_map.iteritems():
source_color = source_dict['Ansi %s Color' % (key)]
if source_color is None:
next
red = int(round(source_color['Red Component'] * 255))
green = int(round(source_color['Green Component'] * 255))
blue = int(round(source_color['Blue Component'] * 255))
orig = dest_dict[value]
dest_dict[value] = (red<<16) + (green<<8) + blue
print 'Updated %s from %s to %s' % (value, orig, dest_dict[value])
plistlib.writePlist(dest_dict, dest_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment