Created
January 26, 2017 02:25
-
-
Save frankrolf/9d7fc229710dbf31b7c078e06159812b to your computer and use it in GitHub Desktop.
Set Robofont’s mark colors to be OSX’s Crayon colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| # Sets Robofont’s Mark Colors to OSX’s Crayon colors. | |
| # Beware: your old colors will be gone (but they were ugly anyway) | |
| from AppKit import NSColorList | |
| from mojo.UI import exportPreferences, importPreferences | |
| from plistlib import readPlist, writePlist | |
| import colorsys | |
| def getRGB(hsva): | |
| # convert hsv color value to rgb | |
| h, s, v, a = hsva | |
| r, g, b = colorsys.hsv_to_rgb(h, s, v) | |
| return (r, g, b, a) | |
| prefs_path = "/tmp/prefs.plist.roboFontSettings" | |
| exportPreferences(prefs_path) | |
| preferences = readPlist(prefs_path) | |
| hsv_colors = [] | |
| rgb_colors = [] | |
| crayons = NSColorList.colorListNamed_("Crayons") | |
| for color_name in crayons.allKeys(): | |
| color = crayons.colorWithKey_(color_name) | |
| (h, s, b, a), name = ( | |
| color.getHue_saturation_brightness_alpha_(None, None, None, None), color_name) | |
| hsv_colors.append([(h, s, b, a), name]) | |
| # sorting the mark colors first by saturation, then by value: | |
| hsv_colors = sorted( | |
| hsv_colors, key=lambda hsba_n: (hsba_n[0][1], hsba_n[0][2])) | |
| for hsv_color, color_name in hsv_colors: | |
| rgb_colors.append([getRGB(hsv_color), color_name]) | |
| rgb_colors.reverse() | |
| preferences['markColors'] = rgb_colors | |
| writePlist(preferences, prefs_path) | |
| importPreferences(prefs_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment