[英]Programmatically changing OS X Menu Bar
I've been looking into a script solution to changing the OS X menu bar to Dark theme from the default. 我一直在寻找一个脚本解决方案,从默认情况下将OS X菜单栏更改为Dark主题。 I know you can access this setting from the System Preferences > General > use dark theme checkbox, but opening System Preferences takes a little too much time for me.
我知道您可以从系统偏好设置>常规>使用暗主题复选框访问此设置,但打开系统偏好设置需要花费一些时间。 Also, I usually run Flux during the night, but kill it during the day, and Flux automatically force changes the menu bar back to default light style (this is why I'm changing it so often, and why I need a faster solution).
此外,我通常在夜间运行Flux,但在白天杀死它,并且Flux会自动强制将菜单栏更改回默认灯光样式(这就是为什么我经常更改它,以及为什么我需要更快的解决方案) 。
I've looked at man defaults
for the Apple OS X system read/write commands, and I finally found the relevant setting: 我查看了Apple OS X系统读/写命令的
man defaults
,最后我找到了相关的设置:
$ defaults read "Apple Global Domain" AppleInterfaceStyle
returns either 返回
Dark
if the style is set to dark, or 如果样式设置为暗,或
The domain/default pair of (kCFPreferencesAnyApplication, AppleInterfaceStyle) does not exist
if it's not (which seems odd that the default would just be an empty attribute). 如果不是(这似乎很奇怪,默认只是一个空属性)。
So I tried: 所以我尝试过:
$ defaults write "Apple Global Domain" AppleInterfaceStyle Dark
This command 'works' (it returns with no errors, exit code 0, trying defaults read
alleges that the "Dark" theme has been set) but doesn't visually change the menu bar or Sherlock style to a dark theme. 此命令“有效”(它返回时没有错误,退出代码0,尝试
defaults read
声称已经设置了“黑暗”主题)但是没有在视觉上将菜单栏或Sherlock样式更改为黑暗主题。 When I check System Preferences > General the checkbox is still unchecked: even re-launching Finder doesn't redraw the menu bar with a dark theme. 当我选中系统偏好设置>常规时,仍然取消选中该复选框:即使重新启动Finder也不会重绘具有黑色主题的菜单栏。
Is there a different command I should be using instead? 我应该使用不同的命令吗? I've checked out
defaults domains
but there doesn't seem to be other relevant domains I should be modifying. 我已经检查了
defaults domains
但似乎没有其他相关域名我应该修改。 Is there a command to force redraw Finder I don't know about? 是否有命令强制重绘Finder我不知道? Or is this a lost cause?
或者这是一个失败的原因?
Thanks! 谢谢!
You can use an AppleScript to do that: 您可以使用AppleScript执行此操作:
Here's the command to use in Terminal (this command toggle between normal and dark mode): 这是在终端中使用的命令(此命令在正常模式和黑暗模式之间切换):
osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'
Another solution: 另一种方案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.