xcodemacosmacos-mojavemacos-darkmode

macOS Mojave : Is there any way to debug an app in dark mode?


I use macOS in Light Mode. I do not like the dark mode.

I am using Xcode. Everything is in light mode and everybody is happy.

I am creating a macOS app and I would like to test the app in dark mode.

Is there a way to pass an argument or something to the app to force it to run in Dark Mode?


Solution

  • Old question but I ran into the same situation today.

    Ideally It would be nice to be able to set a environment variable in you scheme to turn on dark mode.

    So I did some spelunking.

    The setting in Xcode to change Appearance while debugging appears to use a private NSSystemAppearanceProxy object. By setting the appearance of this object from your AppDelegate, you can effect a specific appearance at launch.

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    #if DEBUG // do not include in production code! 
        if ([NSProcessInfo.processInfo.environment[@"UserInterfaceStyle"] isEqualToString:@"Dark"]){
            id proxy = [NSClassFromString(@"NSSystemAppearanceProxy") valueForKey:@"systemProxy"];
            [proxy setValue: [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua] forKey:@"appearance"] ;
        }
    #endif
    }
    

    Then add an environment variable UserInterfaceStyle with the value Dark to your shame. (turn off or on at will)

    Note by setting the appearance on the proxy, rather than the NSApp object, you can still use the runtime appearance setting in Xcode to switch to light mode.