如何检测OS X是否处于暗模式? [英] How to detect if OS X is in dark mode?
问题描述
我的可可应用在新的OS X黑暗模式"下运行时必须更改其行为.
是否可以检测OS X样式是否设置为此模式?
尚不认为可以检测到它,但是您可以使用defaults read
检查OSX是否处于暗模式.
defaults read -g AppleInterfaceStyle
要么返回Dark
(暗模式),要么返回不存在域对.
正如Ken Thomases所说,您可以通过NSUserDefaults访问.GlobalPreferences,因此
NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
如果osxMode为nil
,则它不在暗模式下,但如果osxMode为@"Dark"
,则它处于暗模式下.
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?
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.
这篇关于如何检测OS X是否处于暗模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!