简体   繁体   中英

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. 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).

I've looked at man defaults for the Apple OS X system read/write commands, and I finally found the relevant setting:

$ 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. 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.

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. Is there a command to force redraw Finder I don't know about? Or is this a lost cause?

Thanks!

You can use an AppleScript to do that:

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:

  • See this page to enable the keyboard shortcut ( Command + Option + Control + t ) to switch between Dark and Light modes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM