Skip to content

Instantly share code, notes, and snippets.

@jdamner
Created August 26, 2023 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdamner/14c01237c31e76c5bf2433b5d4f22df5 to your computer and use it in GitHub Desktop.
Save jdamner/14c01237c31e76c5bf2433b5d4f22df5 to your computer and use it in GitHub Desktop.
class Example {
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
Let menubarStringValue = "example"
func updateValue() {
if #available(OSX 10.15, *){
let attributes = [NSAttributedString.Key.font: NSFont.monospacedSystemFont(ofSize: NSFont.systemFontSize(for: self.statusItem.button!.controlSize), weight: NSFont.Weight.medium)]
let attrString = NSAttributedString(string: (self.menubarStringValue), attributes: attributes)
} else {
let attributes = [NSAttributedString.Key.font: NSFont(name: "Monaco", size: NSFont.systemFontSize(for:self.statusItem.button!.controlSize))]
let attrString = NSAttributedString(string: (self.menubarStringValue), attributes: attributes as [NSAttributedString.Key : Any])
}
self.statusItem.button?.attributedTitle = (attrString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment