macOS Mojave:有没有办法在暗模式下调试应用程序?

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

我在轻模式下使用 macOS。我不喜欢深色模式。

我正在使用 Xcode。一切都处于轻模式,每个人都很开心。

我正在创建一个 macOS 应用程序,我想在黑暗模式下测试该应用程序。

有没有办法向应用程序传递参数或其他内容以强制它在黑暗模式下 运行?

您可以在 Automator 中进行快速操作,并将其设为 运行 切换深色模式的 AppleScript。 AppleScript 只是:

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

然后转到 System Preferences - Keyboard - Shortcuts - Services 并将键盘快捷键设置为 运行 您的 AppleScript。

可能有更简单的方法在 Xcode 中传递参数以强制 运行 进入黑暗模式,但这是一个临时解决方案。

老问题,但我今天 运行 遇到了同样的情况。

理想情况下,如果能够在您的方案中设置一个环境变量以打开黑暗模式,那就太好了。

所以我做了一些洞穴探险。

Xcode 中用于在调试时更改 Appea运行ce 的设置似乎使用私有 NSSystemAppearanceProxy 对象。通过从您的 AppDelegate 设置此对象的外观运行ce,您可以在启动时影响特定的外观运行ce。

- (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
}

然后添加一个环境变量 UserInterfaceStyle,其值为 Dark,真可惜。 (随意关闭或打开)

请注意,通过在代理上设置 appea运行ce,而不是 NSApp 对象,您仍然可以使用 Xcode 中的运行时 appea运行ce 设置来切换到 light模式。