Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding OSX battery menu bar item programmatically

I'm trouble finding a way to disable showing the system battery icon on the menu bar. I can disable it from System preferences -> Energy Saver -> "Show battery status in menu bar", but is there a way to achieve the same with a terminal defaults command (or using a simple cocoa app)?

like image 208
Rene Avatar asked Nov 09 '22 02:11

Rene


1 Answers

You can use the defaults way in terminal to just use this and don't forget to use the killall SystemUIServer or to restart/logout & login.

# Menu bar: hide the Time Machine, Volume, User and AirPort (WiFi) icons
for domain in ~/Library/Preferences/ByHost/com.apple.systemuiserver.*; do
defaults write "${domain}" dontAutoLoad -array \
    "/System/Library/CoreServices/Menu Extras/TimeMachine.menu" \
    "/System/Library/CoreServices/Menu Extras/Volume.menu" \
    "/System/Library/CoreServices/Menu Extras/User.menu" \
    "/System/Library/CoreServices/Menu Extras/AirPort.menu"
done
defaults write com.apple.systemuiserver menuExtras -array \
    "/System/Library/CoreServices/Menu Extras/Bluetooth.menu" \
    "/System/Library/CoreServices/Menu Extras/Battery.menu" \
    "/System/Library/CoreServices/Menu Extras/Clock.menu"
killall SystemUIServer

So just move the once you want to hide in the dontAutoLoad array and the ones you wan't visible in the menuExtras array.

like image 157
Bojoer Avatar answered Nov 15 '22 04:11

Bojoer