-
-
Save andrejilderda/8677c565cddc969e6aae7df48622d47c to your computer and use it in GitHub Desktop.
Output system colors from macOS
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
import Cocoa | |
print("\n/* -------------- System Colors -------------- */") | |
// See: https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/color/#system-colors | |
print("systemBlue:", NSColor.systemBlue.rgbaCssString) | |
print("systemBrown:", NSColor.systemBrown.rgbaCssString) | |
print("systemGray:", NSColor.systemGray.rgbaCssString) | |
print("systemGreen:", NSColor.systemGreen.rgbaCssString) | |
print("systemIndigo:", NSColor.systemIndigo.rgbaCssString) | |
print("systemOrange:", NSColor.systemOrange.rgbaCssString) | |
print("systemPink:", NSColor.systemPink.rgbaCssString) | |
print("systemPurple:", NSColor.systemPurple.rgbaCssString) | |
print("systemRed:", NSColor.systemRed.rgbaCssString) | |
print("systemTeal:", NSColor.systemTeal.rgbaCssString) | |
print("systemYellow:", NSColor.systemYellow.rgbaCssString) | |
print("\n/* -------------- Dynamic System Colors -------------- */") | |
// See: https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/color/#dynamic-system-colors | |
print("\n/* Labels */") | |
print("labelColor:", NSColor.labelColor.rgbaCssString) | |
print("secondaryLabelColor:", NSColor.secondaryLabelColor.rgbaCssString) | |
print("tertiaryLabelColor:", NSColor.tertiaryLabelColor.rgbaCssString) | |
print("quaternaryLabelColor:", NSColor.quaternaryLabelColor.rgbaCssString) | |
print("\n/* Text */") | |
print("textColor:", NSColor.textColor.rgbaCssString) | |
print("placeholderTextColor:", NSColor.placeholderTextColor.rgbaCssString) | |
print("selectedTextColor:", NSColor.selectedTextColor.rgbaCssString) | |
print("textBackgroundColor:", NSColor.textBackgroundColor.rgbaCssString) | |
print("selectedTextBackgroundColor:", NSColor.selectedTextBackgroundColor.rgbaCssString) | |
print("keyboardFocusIndicatorColor:", NSColor.keyboardFocusIndicatorColor.rgbaCssString) | |
print("unemphasizedSelectedTextColor:", NSColor.unemphasizedSelectedTextColor.rgbaCssString) | |
print("unemphasizedSelectedTextBackgroundColor:", NSColor.unemphasizedSelectedTextBackgroundColor.rgbaCssString) | |
print("\n/* Content */") | |
print("linkColor:", NSColor.linkColor.rgbaCssString) | |
print("separatorColor:", NSColor.separatorColor.rgbaCssString) | |
print("selectedContentBackgroundColor:", NSColor.selectedContentBackgroundColor.rgbaCssString) | |
print("alternatingContentBackgroundColors[0]:", NSColor.alternatingContentBackgroundColors[0].rgbaCssString) | |
print("alternatingContentBackgroundColors[1]:", NSColor.alternatingContentBackgroundColors[1].rgbaCssString) | |
print("unemphasizedSelectedContentBackgroundColor:", NSColor.unemphasizedSelectedContentBackgroundColor.rgbaCssString) | |
print("\n/* Menus */") | |
print("selectedMenuItemTextColor:", NSColor.selectedMenuItemTextColor.rgbaCssString) | |
print("\n/* Tables */") | |
print("gridColor:", NSColor.gridColor.rgbaCssString) | |
print("headerTextColor:", NSColor.headerTextColor.rgbaCssString) | |
print("\n/* Controls */") | |
print("controlAccentColor:", NSColor.controlAccentColor.rgbaCssString) | |
print("controlColor:", NSColor.controlColor.rgbaCssString) | |
print("controlBackgroundColor:", NSColor.controlBackgroundColor.rgbaCssString) | |
print("controlTextColor:", NSColor.controlTextColor.rgbaCssString) | |
print("disabledControlTextColor:", NSColor.disabledControlTextColor.rgbaCssString) | |
// print("currentControlTint:", NSControlTint.currentControlTint.) | |
print("scrubberTexturedBackground:", NSColor.scrubberTexturedBackground.rgbaCssString) | |
print("selectedControlColor:", NSColor.selectedControlColor.rgbaCssString) | |
print("selectedControlTextColor:", NSColor.selectedControlTextColor.rgbaCssString) | |
print("alternateSelectedControlTextColor:", NSColor.alternateSelectedControlTextColor.rgbaCssString) | |
print("\n/* Windows */") | |
print("windowBackgroundColor:", NSColor.windowBackgroundColor.rgbaCssString) | |
print("windowFrameTextColor:", NSColor.windowFrameTextColor.rgbaCssString) | |
print("underPageBackgroundColor:", NSColor.underPageBackgroundColor.rgbaCssString) | |
print("\n/* Highlights & Shadows */") | |
print("findHighlightColor:", NSColor.findHighlightColor.rgbaCssString) | |
print("highlightColor:", NSColor.highlightColor.rgbaCssString) | |
print("shadowColor:", NSColor.shadowColor.rgbaCssString) | |
// ---------- NSColor extensions ---------- | |
public extension NSColor { | |
// Return as RGBA array, e.g.: `255, 76, 100, 0.5`" | |
// Alpha-rounding code from: https://stackoverflow.com/a/27341001 | |
// String format specifiers per: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW1 | |
var rgbaCssString: String { | |
guard let rgbColor = usingColorSpace(NSColorSpace.deviceRGB) else { | |
return "FFFFFF" | |
} | |
let red = Int(rgbColor.redComponent * 255) | |
let green = Int(rgbColor.greenComponent * 255) | |
let blue = Int(rgbColor.blueComponent * 255) | |
let alpha = String(Double(round(1000 * rgbColor.alphaComponent)/1000)) | |
let rgbaCssString = NSString(format: "%u, %u, %u, %@", red, green, blue, alpha) | |
return rgbaCssString as String | |
} | |
// Return as 6-digit RGB hex, e.g. `CC0000` | |
var hexString: String { | |
guard let rgbColor = usingColorSpace(NSColorSpace.deviceRGB) else { | |
return "FFFFFF" | |
} | |
let red = Int(round(rgbColor.redComponent * 0xFF)) | |
let green = Int(round(rgbColor.greenComponent * 0xFF)) | |
let blue = Int(round(rgbColor.blueComponent * 0xFF)) | |
let hexString = NSString(format: "%02X%02X%02X", red, green, blue) | |
return hexString as String | |
} | |
} |
For macOS Monterey 12.0.1 there were 2 minor changes for:
systemTeal
keyboardFocusIndicatorColor
Output for light theme with default contrast settings (macOS Monterey 12.0.1):
/* -------------- System Colors -------------- */
systemBlue: 0, 122, 255, 1.0
systemBrown: 162, 132, 94, 1.0
systemGray: 142, 142, 147, 1.0
systemGreen: 40, 205, 65, 1.0
systemIndigo: 88, 86, 214, 1.0
systemOrange: 255, 149, 0, 1.0
systemPink: 255, 45, 85, 1.0
systemPurple: 175, 82, 222, 1.0
systemRed: 255, 59, 48, 1.0
systemTeal: 89, 173, 196, 1.0
systemYellow: 255, 204, 0, 1.0
/* -------------- Dynamic System Colors -------------- */
/* Labels */
labelColor: 0, 0, 0, 0.847
secondaryLabelColor: 0, 0, 0, 0.498
tertiaryLabelColor: 0, 0, 0, 0.259
quaternaryLabelColor: 0, 0, 0, 0.098
/* Text */
textColor: 0, 0, 0, 1.0
placeholderTextColor: 0, 0, 0, 0.247
selectedTextColor: 0, 0, 0, 1.0
textBackgroundColor: 255, 255, 255, 1.0
selectedTextBackgroundColor: 179, 215, 255, 1.0
keyboardFocusIndicatorColor: 0, 103, 244, 0.498
unemphasizedSelectedTextColor: 0, 0, 0, 1.0
unemphasizedSelectedTextBackgroundColor: 220, 220, 220, 1.0
/* Content */
linkColor: 0, 104, 218, 1.0
separatorColor: 0, 0, 0, 0.098
selectedContentBackgroundColor: 0, 99, 225, 1.0
alternatingContentBackgroundColors[0]: 255, 255, 255, 1.0
alternatingContentBackgroundColors[1]: 244, 245, 245, 1.0
unemphasizedSelectedContentBackgroundColor: 220, 220, 220, 1.0
/* Menus */
selectedMenuItemTextColor: 255, 255, 255, 1.0
/* Tables */
gridColor: 230, 230, 230, 1.0
headerTextColor: 0, 0, 0, 0.847
/* Controls */
controlAccentColor: 0, 122, 255, 1.0
controlColor: 255, 255, 255, 1.0
controlBackgroundColor: 255, 255, 255, 1.0
controlTextColor: 0, 0, 0, 0.847
disabledControlTextColor: 0, 0, 0, 0.247
scrubberTexturedBackground: FFFFFF
selectedControlColor: 179, 215, 255, 1.0
selectedControlTextColor: 0, 0, 0, 0.847
alternateSelectedControlTextColor: 255, 255, 255, 1.0
/* Windows */
windowBackgroundColor: 236, 236, 236, 1.0
windowFrameTextColor: 0, 0, 0, 0.847
underPageBackgroundColor: 150, 150, 150, 0.898
/* Highlights & Shadows */
findHighlightColor: 255, 255, 0, 1.0
highlightColor: 255, 255, 255, 1.0
shadowColor: 0, 0, 0, 1.0
Output for dark theme with default contrast settings (macOS Monterey 12.0.1):
/* -------------- System Colors -------------- */
systemBlue: 10, 132, 255, 1.0
systemBrown: 172, 142, 104, 1.0
systemGray: 152, 152, 157, 1.0
systemGreen: 50, 215, 75, 1.0
systemIndigo: 94, 92, 230, 1.0
systemOrange: 255, 159, 10, 1.0
systemPink: 255, 55, 95, 1.0
systemPurple: 191, 90, 242, 1.0
systemRed: 255, 69, 58, 1.0
systemTeal: 106, 196, 220, 1.0
systemYellow: 255, 214, 10, 1.0
/* -------------- Dynamic System Colors -------------- */
/* Labels */
labelColor: 255, 255, 255, 0.847
secondaryLabelColor: 255, 255, 255, 0.549
tertiaryLabelColor: 255, 255, 255, 0.247
quaternaryLabelColor: 255, 255, 255, 0.098
/* Text */
textColor: 255, 255, 255, 1.0
placeholderTextColor: 255, 255, 255, 0.247
selectedTextColor: 255, 255, 255, 1.0
textBackgroundColor: 30, 30, 30, 1.0
selectedTextBackgroundColor: 63, 99, 139, 1.0
keyboardFocusIndicatorColor: 26, 169, 255, 0.498
unemphasizedSelectedTextColor: 255, 255, 255, 1.0
unemphasizedSelectedTextBackgroundColor: 70, 70, 70, 1.0
/* Content */
linkColor: 65, 156, 255, 1.0
separatorColor: 255, 255, 255, 0.098
selectedContentBackgroundColor: 0, 88, 208, 1.0
alternatingContentBackgroundColors[0]: 30, 30, 30, 1.0
alternatingContentBackgroundColors[1]: 255, 255, 255, 0.047
unemphasizedSelectedContentBackgroundColor: 70, 70, 70, 1.0
/* Menus */
selectedMenuItemTextColor: 255, 255, 255, 1.0
/* Tables */
gridColor: 26, 26, 26, 1.0
headerTextColor: 255, 255, 255, 1.0
/* Controls */
controlAccentColor: 0, 122, 255, 1.0
controlColor: 255, 255, 255, 0.247
controlBackgroundColor: 30, 30, 30, 1.0
controlTextColor: 255, 255, 255, 0.847
disabledControlTextColor: 255, 255, 255, 0.247
scrubberTexturedBackground: FFFFFF
selectedControlColor: 63, 99, 139, 1.0
selectedControlTextColor: 255, 255, 255, 0.847
alternateSelectedControlTextColor: 255, 255, 255, 1.0
/* Windows */
windowBackgroundColor: 50, 50, 50, 1.0
windowFrameTextColor: 255, 255, 255, 0.847
underPageBackgroundColor: 40, 40, 40, 1.0
/* Highlights & Shadows */
findHighlightColor: 255, 255, 0, 1.0
highlightColor: 180, 180, 180, 1.0
shadowColor: 0, 0, 0, 1.0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this script:
swift system-colors.swift
Output for light theme with default contrast settings (macOS Big Sur 11.2.3):
Output for dark theme with default contrast settings (macOS Big Sur 11.2.3):