-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
terminal_interface_mode_switcher.swift
executable file
·50 lines (41 loc) · 1.32 KB
/
terminal_interface_mode_switcher.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
46
47
48
49
50
#!/usr/bin/env swift
import Cocoa
let app = NSApplication.shared
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
DistributedNotificationCenter.default.addObserver(
self,
selector: #selector(interfaceModeChanged(sender:)),
name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"),
object: nil
)
}
@objc func interfaceModeChanged(sender: NSNotification) {
let mode = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") ?? "Light"
let script: String!
if mode == "Dark" {
script = """
tell application "Terminal"
set default settings to settings set "Solarized Dark"
set current settings of tabs of windows to settings set "Solarized Dark"
end tell
"""
} else {
script = """
tell application "Terminal"
set default settings to settings set "Solarized Light"
set current settings of tabs of windows to settings set "Solarized Light"
end tell
"""
}
print(mode)
var error: NSDictionary?
NSAppleScript(source: script)!.executeAndReturnError(&error)
if let error = error {
fputs("\(error)\n", stderr)
}
}
}
let delegate = AppDelegate()
app.delegate = delegate
app.run()