Hi, since macOS dark mode was originally offered, I've been using the following technique to detect the Dark/Light Desktop theme:
Recently with the upgrade to Big Sur, the menu bar and system tray area goes light/dark based on the wallpaper, NOT based on the Desktop preference.
How do I detect this so that I can change my app's System Tray icon to match the os behavior?
Code Block defaults read -g AppleInterfaceStyle
Recently with the upgrade to Big Sur, the menu bar and system tray area goes light/dark based on the wallpaper, NOT based on the Desktop preference.
How do I detect this so that I can change my app's System Tray icon to match the os behavior?
I began writing a crude luminosity test based on the top-left pixel of the screen. Here's a the test, written in Java:
This has some unfortunate side effects:
I assume Apple offers an API, it's just not well known yet. Where would I be able to find API information about this feature?
Code Block java public static boolean isDarkTaskbar() { try { Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); Rectangle topCorner = new Rectangle(rectangle.x, rectangle.y, 1, 1); BufferedImage pixel = new Robot().createScreenCapture(topCorner); Color color = new Color(pixel.getRGB(0, 0)); return (color.getRed() * 0.299) + (color.getGreen() * 0.587) + (color.getBlue() * 0.114) <= 174; } catch(AWTException e) { log.warn("Unable to detect dark taskbar: {}", e.getMessage()); } return false; }
This has some unfortunate side effects:
It triggers the "Screen recording" security prompt, something I'd rather not do.
It doesn't work 100% of the time. Some wallpapers such as "Catalina Silhouette" switch the taskbar to "Light Mode" for seemingly no good reason. Preview: i.imgur.com/eiWa864.png
I assume Apple offers an API, it's just not well known yet. Where would I be able to find API information about this feature?