I had the same problem, solving it, calling the command defaults read
and analyzing the exit code:
private boolean isMacMenuBarDarkMode() {
try {
final Process proc = Runtime.getRuntime().exec(new String[] {"defaults", "read", "-g", "AppleInterfaceStyle"});
proc.waitFor(100, TimeUnit.MILLISECONDS);
return proc.exitValue() == 0;
} catch (IOException | InterruptedException | IllegalThreadStateException ex) {
LOG.warn("Could not determine, whether 'dark mode' is being used. Falling back to default (light) mode.");
return false;
}
}
java.awt.TrayIcon:
final Image image;
if (isMacMenuBarDarkMode()) {
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_darkmode.png"));
} else {
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_default.png"));
}