Skip to content

Instantly share code, notes, and snippets.

@kssreeram
Created December 26, 2020 17:54
Show Gist options
  • Save kssreeram/4df35007b185a3e9fce37b04e9afc4bc to your computer and use it in GitHub Desktop.
Save kssreeram/4df35007b185a3e9fce37b04e9afc4bc to your computer and use it in GitHub Desktop.
#import <AppKit/AppKit.h>
int main() {
while (1) {
NSColor *color1 = [NSColor textColor];
NSColor *color2 = [color1 colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
CGFloat r, g, b, a;
[color2 getRed:&r green:&g blue:&b alpha:&a];
printf("text-color: (%f, %f, %f, %f)\n", r, g, b, a);
[NSThread sleepForTimeInterval:1.0];
}
return 0;
}
@kssreeram
Copy link
Author

Compile with clang text-color.m -framework AppKit.

When the program starts, it displays the correct RGB values for the system text color. But if the system appearance is switched (say from light to dark) while the program is running, the printed value doesn't change accordingly.

How do I fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment