-
Notifications
You must be signed in to change notification settings - Fork 1
/
observer.swift
executable file
·45 lines (38 loc) · 1.04 KB
/
observer.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env DYLD_FRAMEWORK_PATH=/System/Library/Frameworks /usr/bin/swift
/*
*
* observer.swift
*
* Swift script to observe macOS color scheme changes
*
*/
import Cocoa
extension Notification.Name {
static let AppleInterfaceThemeChangedNotification = Notification.Name("AppleInterfaceThemeChangedNotification")
}
func styleChange() {
let currentScheme = UserDefaults
.standard
.string(forKey: "AppleInterfaceStyle") ?? "Light"
let mode = currentScheme == "Dark" ? "0" : "1"
print(mode)
fflush(stdout)
}
/* Initial check */
styleChange()
/* Observe interface changes */
DistributedNotificationCenter
.default
.addObserver(
forName: .AppleInterfaceThemeChangedNotification,
object: nil,
queue: nil) { (notification) in styleChange() }
/* Check interface on wake */
NSWorkspace
.shared
.notificationCenter
.addObserver(
forName: NSWorkspace.didWakeNotification,
object: nil,
queue: nil) { (notification) in styleChange() }
NSApplication.shared.run()