Skip to content

Instantly share code, notes, and snippets.

Created November 1, 2019 04:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import Cocoa
import SwiftUI
import ServiceManagement
class AppDelegate: NSObject, NSApplicationDelegate {
var statusBarItem: NSStatusItem!
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
let statusBar = NSStatusBar.system
statusBarItem = statusBar.statusItem(
withLength: NSStatusItem.squareLength)
let statusBarMenu = NSMenu(title: "Cap Status Bar Menu") = statusBarMenu
statusBarItem.button?.title = DarkMode.isEnabled ? "☀️" : "🌘"
withTitle: "Toggle DarkMode",
action: #selector(AppDelegate.toggle),
keyEquivalent: "")
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
@objc func toggle() {
print("Attempting to toggle")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment