MacOS – Can “defaults write” command line configure the menu bar on macOS

command linedefaultsmacosterminal

I would really like to use a script to enable these things on macOS High Sierra, by using defaults. I know how to create the script in .bash_profile, as I will use a function for it, and then just run the function in the terminal. However, what I'm missing are the actual strings to enable the following:

  • Displaying of Bluetooth icon
  • Displaying of Volume icon
  • Displaying of battery percentage
  • Displaying of full date

Are any of these programmatically settable by using Defaults, and have they changed a great deal between 10.6-10.13?

Ok, based on what IconDeamon said in the comments section for this post, I was able to go and edit ~/Library/Preferences/com.apple.systemuiserver.plist and was able to see a list of menus that I have enabled.

However, this does not necessarily take me to the place I want to go to. Ideally, it'd be good to find a list and be able to solve this. I mean, okay, now, thanks to help on this forum, I know that the ones I wish to display are:

/System/Library/CoreServices/Menu Extras/Script Menu.menu

/System/Library/CoreServices/Menu Extras/RemoteDesktop.menu

/System/Library/CoreServices/Menu Extras/Bluetooth.menu

/System/Library/CoreServices/Menu Extras/TimeMachine.menu

/System/Library/CoreServices/Menu Extras/AirPort.menu

/System/Library/CoreServices/Menu Extras/TextInput.menu

/System/Library/CoreServices/Menu Extras/Battery.menu

/System/Library/CoreServices/Menu Extras/Volume.menu

/System/Library/CoreServices/Menu Extras/Clock.menu

and that the menu can have a _5 or a _3 at the end to signify where it should go. But..? It's not exactly a user-writable textfile I can just edit.

Best Answer

This defaults write command will enable several menu-bar icons, including Bluetooth.

defaults write com.apple.systemuiserver menuExtras -array \
"/System/Library/CoreServices/Menu Extras/AirPort.menu" \
"/System/Library/CoreServices/Menu Extras/Bluetooth.menu" \
"/System/Library/CoreServices/Menu Extras/Clock.menu" \
"/System/Library/CoreServices/Menu Extras/Displays.menu" \
"/System/Library/CoreServices/Menu Extras/Volume.menu"

Changes will not take effect until you restart the SystemUIServer:
killall SystemUIServer

If you want to enable additional items, look in ~/Library/Preferences/com.apple.systemuiserver.plist to find the specific name of the menu extra you are seeking.

Note: If you attempt to enable a menu extra that you do not have on your machine, the command will get stuck in an endless loop. Some users may not have the Eject.menu, for example.