0

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?

Duck
  • 34,902
  • 47
  • 248
  • 470

2 Answers2

4

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.

smorr
  • 76
  • 2
1

You can make a Quick Action in Automator and make it run an AppleScript that toggles dark mode. The AppleScript is just:

tell application "System Events"
    tell appearance preferences
        set dark mode to not dark mode
    end tell
end tell

Then go to System Preferences - Keyboard - Shortcuts - Services and set a keyboard shortcut to run your AppleScript.

There might be an easier way to pass an argument in Xcode to force run in dark mode, but this is a temporary solution.

akmin04
  • 677
  • 6
  • 14
  • Thanks. That may be not the ideal solution but I think it may be the only one for now. THANKS – Duck Dec 30 '18 at 12:12