Skip to content

Instantly share code, notes, and snippets.

@arrowtype
Last active May 25, 2021 18:30
Show Gist options
  • Save arrowtype/268bb9db71231ca4fc39143760e94947 to your computer and use it in GitHub Desktop.
Save arrowtype/268bb9db71231ca4fc39143760e94947 to your computer and use it in GitHub Desktop.
"""
A RoboFont script to check if "dark mode" is currently active and apply dark preferences in RoboFont if so.
Works best if set up as a "Start Up Script." Here’s how to make it one:
1. Open RoboFont > Preferences
2. Go to Extensions > Start Up Scripts
3. Click the "+" icon, then add this script
4. Click "Apply" to save setting changes
5. Restart RoboFont!
----
Possible Script To-Do Items:
- Auto-switch light/dark when OS setting changed. Possibly: run script every n seconds to automatically catch if the light/dark mode changes.
- Handle Font View colors better (this is somewhat limited by RoboFont itself, but may may have a clever solution or improve over time).
"""
# -------------------------------------------------
# get darkmode pref
from Foundation import NSUserDefaults
darkmode = True if NSUserDefaults.standardUserDefaults().stringForKey_('AppleInterfaceStyle') == "Dark" else False
print(f"🤖 Startup Script: Setting darkmode to {darkmode}")
# -------------------------------------------------
# set appearance
import AppKit
def setDark():
dark = AppKit.NSAppearance.appearanceNamed_(AppKit.NSAppearanceNameDarkAqua)
AppKit.NSApp().setAppearance_(dark)
def setLight():
aqua = AppKit.NSAppearance.appearanceNamed_(AppKit.NSAppearanceNameAqua)
AppKit.NSApp().setAppearance_(aqua)
if darkmode:
setDark()
else:
setLight()
# ------------------------------------------------------------------------------
# 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]]
def setDarkFontView():
if set(currentDefault) == set(darkSetting):
pass
else:
for pref in darkFontView:
setDefault(pref, darkFontView[pref])
def setLightFontView():
if set(currentDefault) == set(darkSetting):
for pref in defaultFontView:
setDefault(pref, defaultFontView[pref])
else:
pass
if darkmode:
setDarkFontView()
else:
setLightFontView()
preferencesChanged()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment