-
Notifications
You must be signed in to change notification settings - Fork 0
/
macos_theme.m
37 lines (33 loc) · 1.02 KB
/
macos_theme.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
37
#import <AppKit/AppKit.h>
#include <stdio.h>
#include <string.h>
static void usage() {
puts("Usage: macos_theme [-n | --name]\n"
"No args - Prints current theme, 'dark' or 'light'.\n"
"-n | --name - Prints current NSAppearanceName.");
}
int main(int argc, char **argv) {
NSString *light = @"NSAppearanceNameAqua";
NSString *dark = @"NSAppearanceNameDarkAqua";
NSApplication *app = [NSApplication sharedApplication];
NSAppearance *appearance = [app effectiveAppearance];
if (argc == 1) {
NSAppearanceName bestFit =
[appearance bestMatchFromAppearancesWithNames:@[light, dark]];
puts([bestFit characterAtIndex:16] == 'D' ? "dark" : "light");
} else if (argc == 2) {
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
usage();
} else if (!strcmp(argv[1], "-n") || !strcmp(argv[1], "--name")) {
NSAppearanceName name = [appearance name];
puts(name.UTF8String);
} else {
usage();
return 1;
}
} else {
usage();
return 1;
}
return 0;
}