Catalina can not detect dark mode through AppleInterfaceStyle

In Mojave even if your application did not target the 10.14 SDK you could detect with the OS itself was in dark mode by reading the "AppleInterfaceStyle" userdefault. With the introduction of "Auto" in Catalina this is no longer the case as when "Auto" is activated the value of "AppleInterfaceStyle" is not updated to "Dark" appropriately.


Does anyone know a different trick that works in catalina to read this pref when you can't guaruntee the application you're running in is targetting >= 10.14 SDK (to get access to the correct effectiveAppearance).

NSAppearance currentAppearance

Hey 👏


you need to combine `AppleInterfaceStyle` witthissi new value introduced in macOS Catalina `AppleInterfaceStyleSwitchesAutomatically`.


Here is some pseudo-code explaining how to:



theme = light //default is light
if macOS_10.15
   if UserDefaults(AppleInterfaceStyleSwitchesAutomatically) == TRUE
      if UserDefaults(AppleInterfaceStyle) == NIL≤
         theme = dark // is nil, means it's dark and will switch in future to light     
      else
         theme = light //means it's light and will switch in future to dark
      endif
  else
     if UserDefaults(AppleInterfaceStyle) == NIL
        theme = light
     else
        theme = dark
     endif
  endif
else if macOS_10.14
   if UserDefaults(AppleInterfaceStyle) == NIL
      theme = light
   else
     theme = dark
   endif
endif



You can check a macOS sample app here: https://github.com/ruiaureliano/macOS-Appearance.


Cheers 💪


---

Catalina can not detect dark mode through AppleInterfaceStyle
 
 
Q