The (Annoying) Way To Get the Current MacOS Appearance Scheme From the Command Line

The (Annoying) Way To Get the Current MacOS Appearance Scheme From the Command Line

Ok, here’s something bizarre.

I’m trying to get the current MacOS appearance scheme — either light or dark mode — from the terminal. The way to do this is by running this command (source):

defaults read -g AppleInterfaceStyle

If MacOS is in dark mode, this will print Dark. But if MacOS is in light mode, the command will print… an error:

2022-10-04 09:15:18.058 defaults[35844:466643] 
The domain/default pair of (kCFPreferencesAnyApplication, AppleInterfaceStyle) does not exist

Running defaults read -g confirms what the error message says: the AppleInterfaceStyle key is not set when MacOS is in light mode.

Why was this chosen as the way to do things? Now I need to capture and parse stderr just confirm that the reason an error occurred was because MacOS is in light mode; as oppose to some other, possibly legitimate, reason.

A tad annoying I must say.