forked from sindresorhus/dark-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdark-mode.m
36 lines (28 loc) · 1.19 KB
/
dark-mode.m
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
@import Foundation;
int main() {
@autoreleasepool {
NSArray *args = [[NSProcessInfo processInfo] arguments];
NSString *mode = CFBridgingRelease(CFPreferencesCopyValue((CFStringRef)@"AppleInterfaceStyle", kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost));
NSString *newMode = [mode isEqualToString: @"Dark"] ? @"Light" : @"Dark";
if (args.count > 1) {
if ([args[1] isEqualToString: @"--version"]) {
puts("1.0.1");
return 0;
}
if ([args[1] isEqualToString: @"--help"]) {
puts("\n Usage:\n dark-mode [--mode]\n\n Options:\n --mode Get or set the mode: Dark|Light\n\n Created by Sindre Sorhus");
return 0;
}
if ([args[1] isEqualToString: @"--mode"]) {
if (args.count == 2) {
printf("%s\n", [mode UTF8String]);
return 0;
}
newMode = args[2];
}
}
CFPreferencesSetValue((CFStringRef)@"AppleInterfaceStyle", (__bridge CFPropertyListRef)(newMode), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), (CFStringRef)@"AppleInterfaceThemeChangedNotification", NULL, NULL, YES);
}
return 0;
}