Skip to content

Instantly share code, notes, and snippets.

@will
Last active March 9, 2022 16:25
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 will/7bff98e86fe95524e86389c1c867b124 to your computer and use it in GitHub Desktop.
Save will/7bff98e86fe95524e86389c1c867b124 to your computer and use it in GitHub Desktop.
print light mode dark mode changes
import Foundation
import AppKit
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
DistributedNotificationCenter.default.addObserver(
forName: Notification.Name("AppleInterfaceThemeChangedNotification"),
object: nil, queue: nil,
using: self.themeChanged(notification:)
)
}
func themeChanged(notification: Notification) {
let dark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark"
print(dark ? "dark" : "light")
fflush(__stdoutp)
}
}
let app = NSApplication.shared
let del = AppDelegate()
app.delegate = del
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment