Search code examples
macoscocoathemes

How to detect if OS X is in dark mode?


My cocoa app has to change its behaviour when run in the new OS X "dark mode".

Is there a way to detect if OS X style is set to this mode?


Solution

  • Don't think there's a cocoa way of detecting it yet, however you can use defaults read to check whether or not OSX is in dark mode.

    defaults read -g AppleInterfaceStyle
    

    Either returns Dark (dark mode) or returns domain pair does not exist.

    EDIT:

    As Ken Thomases said you can access .GlobalPreferences via NSUserDefaults, so

    NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
    

    If osxMode is nil then it isn't in dark mode, but if osxMode is @"Dark" then it is in dark mode.