Last active
February 3, 2022 05:57
-
-
Save arrowtype/ce0cee426f47c2fe7e82aa07d1e0a450 to your computer and use it in GitHub Desktop.
A script to toggle darkmode in RoboFont, for app UI and Font View. Also includes a dark theme for the RoboFont Theme Editor.
This file contains 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
""" | |
Toggle a dark mode in RoboFont. | |
For a dark mode in the Glyph Edit view, install Theme Editor: | |
https://github.com/connordavenport/Theme-Manager | |
...and import the "Dark Connor" theme from this Gist | |
(https://gist.github.com/arrowtype/ce0cee426f47c2fe7e82aa07d1e0a450). | |
Also offers to edit the markColor of glyphs with a high opacity in their markColor, | |
which will disrupt the visual effect of a dark mode on the Font View. However, | |
this only works for currently-open UFOs, and will edit your glyf data, so you may wish | |
to answer "No" to this option (or remove it from your copy of the script). | |
""" | |
# ------------------------------------------------------------------------------ | |
# Toggle app UI dark mode. Thanks to @gferreira at: | |
# https://forum.robofont.com/topic/565/activating-dark-mode-in-macos-10-14-rf-3-2?_=1588526372627 | |
import AppKit | |
aqua = AppKit.NSAppearance.appearanceNamed_(AppKit.NSAppearanceNameAqua) | |
dark = AppKit.NSAppearance.appearanceNamed_(AppKit.NSAppearanceNameDarkAqua) | |
if AppKit.NSApp().appearance() == aqua: | |
appearance = dark | |
elif AppKit.NSApp().appearance() == dark: | |
appearance = aqua | |
else: | |
# custom appearance | |
appearance = aqua | |
if appearance: | |
AppKit.NSApp().setAppearance_(appearance) | |
# ------------------------------------------------------------------------------ | |
# toggle fontview dark mode | |
from mojo.UI import getDefault, setDefault, preferencesChanged | |
defaultFontView = { | |
# Header line separator color | |
"glypHCellHeaderLineColor": [0, 0, 0, 0.2], | |
# Alternative text color | |
"glyphCellAlternateTextColor": [1, 1, 1, 1], | |
# Background color | |
"glyphCellBackgroundColor": [1, 1, 1, 1], | |
# Glyph changed color | |
"glyphCellChangedColor": [0.3, 0.3, 0.3, 0.8], | |
# Glyph changed highlight color | |
"glyphCellChangedHighlightColor": [0.4, 0.4, 0.4, 0.8], | |
# Glyph color | |
"glyphCellGlyphColor": [0, 0, 0, 1], | |
# Default glyph layer color | |
"glyphCellGlyphLayerDefaultColor": [0.5, 0.5, 0.5, 0.7], | |
# Header color | |
"glyphCellHeaderColor": [0.6, 0.6, 0.6, 0.4], | |
# Header highlight color | |
"glyphCellHeaderHighlightColor": [0.7, 0.7, 0.7, 0.4], | |
# Layer indicator color | |
"glyphCellLayerIndicatorColor": [0.5, 0, 0.5, 0.7], | |
# Metrics color | |
"glyphCellMetricsColor": [0, 0, 0, 0.08], | |
# Metrics line color | |
"glyphCellMetricsLineColor": [0, 0, 0, 0.08], | |
# Note indicator color | |
"glyphCellNoteIndicatorColor": [0.5, 0.5, 0.5, 1], | |
# Skip glyph export indicator color | |
"glyphCellSkipExportIndicatorColor": [0.9, 0.17, 0.3, 1], | |
# Template glyph cell background color | |
"glyphCellTemplateGlyphBackgroundColor": [0.9, 0.9, 0.9, 1], | |
# Template text color | |
"glyphCellTemplateGlyphTextColor": [1, 1, 1, 1], | |
# Template text shadow color | |
"glyphCellTemplateGlyphTextShadowColor": [0.6, 0.6, 0.6, 1], | |
# Text color | |
"glyphCellTextColor": [0.22, 0.22, 0.27, 1], | |
# Unicode replace character for template glyphs | |
"glyphCellViewUnicodeReplacement": "✍", | |
# Collection background color | |
"glyphCollectionBackgroundColor": [0.6, 0.6, 0.6, 1], | |
# Collection grid color | |
"glyphCollectionGridColor": [0.6, 0.6, 0.6, 1] | |
} | |
darkFontView = { | |
# Header line separator color | |
"glypHCellHeaderLineColor": [0, 0, 0, 0.5], | |
# Alternative text color | |
"glyphCellAlternateTextColor": [0.15, 0.15, 0.15, 1], | |
# Background color | |
#"glyphCellBackgroundColor": [0.07, 0.07, 0.07, 1], | |
"glyphCellBackgroundColor": [0.07, 0.07, 0.07, 1], | |
# Glyph changed color | |
"glyphCellChangedColor": [0.83, 0.58, 0, 1], | |
# Glyph changed highlight color | |
"glyphCellChangedHighlightColor": [1, 0.69, 0, 1], | |
# Glyph color | |
"glyphCellGlyphColor": [1, 1, 1, 1], | |
# Default glyph layer color | |
"glyphCellGlyphLayerDefaultColor": [0.7, 0.7, 0.7, 0.7], | |
# Header color | |
"glyphCellHeaderColor": [0.15, 0.15, 0.15, 1], | |
# Header highlight color | |
"glyphCellHeaderHighlightColor": [0.18, 0.18, 0.18, 1], | |
# Layer indicator color | |
"glyphCellLayerIndicatorColor": [0, 0.36, 1, 0.7], | |
# Metrics color | |
"glyphCellMetricsColor": [0, 0, 0, 0.08], | |
# Metrics line color | |
"glyphCellMetricsLineColor": [0, 0, 0, 0.08], | |
# Note indicator color | |
"glyphCellNoteIndicatorColor": [0.5, 0.5, 0.5, 1], | |
# Skip glyph export indicator color | |
"glyphCellSkipExportIndicatorColor": [0.9, 0.17, 0.3, 1], | |
# Template glyph cell background color | |
"glyphCellTemplateGlyphBackgroundColor": [0, 0, 0, 1], | |
# Template text color | |
"glyphCellTemplateGlyphTextColor": [0.28, 0.28, 0.28, 1], | |
# Template text shadow color | |
"glyphCellTemplateGlyphTextShadowColor": [0, 0, 0, 1], | |
# Text color | |
"glyphCellTextColor": [1, 1, 1, 1], | |
# Unicode replace character for template glyphs | |
"glyphCellViewUnicodeReplacement": "✐", | |
# Collection background color | |
"glyphCollectionBackgroundColor": [0.05, 0.05, 0.05, 1], | |
# Collection grid color | |
"glyphCollectionGridColor": [0, 0, 0, 1], | |
# Collection grid color | |
"glyphCollectionGridColor": [0, 0, 0, 1] | |
} | |
currentDefault = list(getDefault(list(darkFontView.keys())[0])) | |
darkSetting = [float(num) for num in list(darkFontView.values())[0]] | |
if set(currentDefault) == set(darkSetting): | |
for pref in defaultFontView: | |
setDefault(pref, defaultFontView[pref]) | |
else: | |
for pref in darkFontView: | |
setDefault(pref, darkFontView[pref]) | |
preferencesChanged() | |
# ------------------------------------------------------------------------------ | |
# toggle faded markColors | |
from mojo.UI import AskYesNoCancel | |
highOpacityMarks = False | |
for f in AllFonts(): | |
for g in f: | |
if g.markColor and [c for c in g.markColor][3] >= 0.6: | |
highOpacityMarks = True | |
if highOpacityMarks: | |
changeMarks = AskYesNoCancel("\ | |
\ Do you wish to change high-opacity mark colors to to let dark theme work ideally? \ | |
\ Note: this edits the .glyf files in the current UFO, but only needs to be done once.") | |
try: | |
if changeMarks == True: | |
markOpacity = 0.5 | |
for f in AllFonts(): | |
for g in f: | |
if g.markColor: | |
if [c for c in g.markColor][3] >= 0.6: | |
newColor = tuple([c[1] for c in enumerate(g.markColor) if (c[0] < 3)] + [markOpacity]) | |
g.markColor = newColor | |
except NameError: | |
pass | |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>glyphViewAlternateFillColor</key> | |
<array> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.6027</real> | |
</array> | |
<key>glyphViewAnchorColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewAnchorTextColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewBackgroundColor</key> | |
<array> | |
<real>0.2298</real> | |
<real>0.2408</real> | |
<real>0.2707</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewBitmapColor</key> | |
<array> | |
<real>0.3903</real> | |
<real>0.3903</real> | |
<real>0.3903</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewBluesColor</key> | |
<array> | |
<real>0.1254</real> | |
<real>0.9809</real> | |
<real>0.9693</real> | |
<real>0.1147</real> | |
</array> | |
<key>glyphViewComponentFillColor</key> | |
<array> | |
<real>0.1484</real> | |
<real>0.9538</real> | |
<real>0.6962</real> | |
<real>0.313</real> | |
</array> | |
<key>glyphViewComponentInfoColor</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewComponentStrokeColor</key> | |
<array> | |
<real>0.0</real> | |
<real>0.0281126968503937</real> | |
<real>1.0</real> | |
<real>0.6860619288511749</real> | |
</array> | |
<key>glyphViewContourIndexColor</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewCornerPointsFill</key> | |
<array> | |
<real>0.9900003671646118</real> | |
<real>0.47194594144821167</real> | |
<real>0.032503124326467514</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewCornerPointsStroke</key> | |
<array> | |
<real>0.9868893623352051</real> | |
<real>0.1778077334165573</real> | |
<real>0.02847931534051895</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewCurvePointsFill</key> | |
<array> | |
<real>0.0</real> | |
<real>0.7527</real> | |
<real>0.8563</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewCurvePointsStroke</key> | |
<array> | |
<real>0.4973</real> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewEchoStrokeColor</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>0.6328</real> | |
</array> | |
<key>glyphViewFamilyBluesColor</key> | |
<array> | |
<real>0.1331</real> | |
<real>0.9816</real> | |
<real>0.9394</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewFillColor</key> | |
<array> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewGlobalGuidesColor</key> | |
<array> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.998193621635437</real> | |
<real>0.4</real> | |
</array> | |
<key>glyphViewGridColor</key> | |
<array> | |
<real>0.7187</real> | |
<real>0.7187</real> | |
<real>0.7187</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewHandlesQuadStrokeColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.8</real> | |
</array> | |
<key>glyphViewHandlesStrokeColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.923</real> | |
<real>0.6066</real> | |
<real>0.2171</real> | |
</array> | |
<key>glyphViewHandlesStrokeWidth</key> | |
<integer>2</integer> | |
<key>glyphViewImageInfoColor</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewLocalGuidesColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.3986247859589041</real> | |
</array> | |
<key>glyphViewMarginColor</key> | |
<array> | |
<real>0.0215</real> | |
<real>0.0021</real> | |
<real>0.0025</real> | |
<real>0.1083</real> | |
</array> | |
<key>glyphViewMeasurementsBackgroundColor</key> | |
<array> | |
<real>0.8245</real> | |
<real>0.875</real> | |
<real>1.0</real> | |
<real>0.1953</real> | |
</array> | |
<key>glyphViewMeasurementsForgroundColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.2</real> | |
<real>1.0</real> | |
<real>0.7340384301566579</real> | |
</array> | |
<key>glyphViewMeasurementsTextColor</key> | |
<array> | |
<real>0.9086</real> | |
<real>0.863</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewMetricsColor</key> | |
<array> | |
<real>0.8672</real> | |
<real>0.8773</real> | |
<real>0.8771</real> | |
<real>0.5</real> | |
</array> | |
<key>glyphViewMetricsTitlesColor</key> | |
<array> | |
<real>0.7063</real> | |
<real>0.7063</real> | |
<real>0.7063</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewOffCurvePointsFill</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewOffCurvePointsSize</key> | |
<real>2.0</real> | |
<key>glyphViewOffCurvePointsStroke</key> | |
<array> | |
<real>1.0</real> | |
<real>0.6668</real> | |
<real>0.2573</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewOffCurveQuadPointsStroke</key> | |
<array> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.8</real> | |
</array> | |
<key>glyphViewOncurvePointsSize</key> | |
<real>3.0</real> | |
<key>glyphViewOpenStartPointsArrowColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewOutlineErrorsColor</key> | |
<array> | |
<real>0.2</real> | |
<real>0.8</real> | |
<real>1.0</real> | |
<real>0.8</real> | |
</array> | |
<key>glyphViewPointCoordinateBackgroundColor</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewPointCoordinateColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.9655</real> | |
<real>0.6804</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewPointIndexColor</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewPreviewBackgroundColor</key> | |
<array> | |
<real>0.639</real> | |
<real>0.639</real> | |
<real>0.639</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewPreviewFillColor</key> | |
<array> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>0.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewSegmentIndexColor</key> | |
<array> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewSelectionColor</key> | |
<array> | |
<real>0.0602104589343071</real> | |
<real>0.5068462491035461</real> | |
<real>0.998458981513977</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewSelectionMarqueColor</key> | |
<array> | |
<real>0.0</real> | |
<real>1.0</real> | |
<real>0.6</real> | |
<real>0.0764523498694517</real> | |
</array> | |
<key>glyphViewSelectionStrokeWidth</key> | |
<integer>3</integer> | |
<key>glyphViewSmoothPointStroke</key> | |
<array> | |
<real>0.0917</real> | |
<real>0.0</real> | |
<real>0.8563</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewStartPointsArrowColor</key> | |
<array> | |
<real>1.0</real> | |
<real>0.0</real> | |
<real>0.7428</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewStrokeColor</key> | |
<array> | |
<real>0.6037</real> | |
<real>0.7178</real> | |
<real>1.0</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewStrokeWidth</key> | |
<integer>1</integer> | |
<key>glyphViewTangentPointsFill</key> | |
<array> | |
<real>0.9034</real> | |
<real>0.5904</real> | |
<real>0.9101</real> | |
<real>1.0</real> | |
</array> | |
<key>glyphViewTangentPointsStroke</key> | |
<array> | |
<real>0.9767</real> | |
<real>0.0</real> | |
<real>0.9491</real> | |
<real>1.0</real> | |
</array> | |
<key>themeName</key> | |
<string>Dark Connor</string> | |
<key>themeType</key> | |
<string>User</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rather than hard-coding the prefs into that first script, I was having some luck with this below. This way, you can keep tweaking the prefs in the native UI, and it will keep everything (associated with the respective theme you were editing them in...).