feat: add system theme toggle command

This commit is contained in:
2026-10-18 18:42:03 +02:00
parent cead6d9382
commit a68694e66b
8 changed files with 146 additions and 10 deletions
+28
View File
@@ -0,0 +1,28 @@
import Foundation
enum SystemTheme {
static func toggle() async throws {
try await Task.detached {
guard let script = NSAppleScript(source: """
tell application "System Events"
tell appearance preferences
set dark mode to not dark mode
end tell
end tell
""") else {
throw NSError(domain: "Conjure.SystemTheme", code: 1, userInfo: [
NSLocalizedDescriptionKey: "Couldn’t create the system appearance script.",
])
}
var error: NSDictionary?
script.executeAndReturnError(&error)
if let error {
let code = error[NSAppleScript.errorNumber] as? Int ?? 1
let message = code == -1743
? "Allow Conjure to control System Events in System Settings → Privacy & Security → Automation, then try again."
: error[NSAppleScript.errorMessage] as? String ?? "macOS couldn’t change the system appearance."
throw NSError(domain: "Conjure.SystemTheme", code: code, userInfo: [NSLocalizedDescriptionKey: message])
}
}.value
}
}