Last active
March 9, 2022 16:25
-
-
Save will/7bff98e86fe95524e86389c1c867b124 to your computer and use it in GitHub Desktop.
print light mode dark mode changes
This file contains hidden or 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 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