Created
July 15, 2024 03:55
-
-
Save CtrliPhones/303d78b3217cc05f3b4262a792729df9 to your computer and use it in GitHub Desktop.
Displays your current macOS accent color as a hex code
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
// This returns a hex code for your current macOS system accent color, basically a snippet straight from my Weave browser. | |
// You can compile this as a command line tool, which is what I did. | |
import Foundation | |
import AppKit | |
extension NSColor { | |
var hexString: String { | |
guard let rgbColor = usingColorSpace(NSColorSpace.sRGB) else { return "#000000" } | |
let red = Int(rgbColor.redComponent * 255.0) | |
let green = Int(rgbColor.greenComponent * 255.0) | |
let blue = Int(rgbColor.blueComponent * 255.0) | |
return String(format: "#%02X%02X%02X", red, green, blue) | |
} | |
static var systemAccentColor: NSColor { | |
return NSColor.controlAccentColor | |
} | |
} | |
let sysAccent = NSColor.systemAccentColor.hexString | |
print(sysAccent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment