简体   繁体   English

以编程方式隐藏OSX电池菜单栏项

[英]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)? 我可以从系统偏好设置 - >节能器 - >“在菜单栏中显示电池状态”中禁用它,但有没有办法用终端defaults命令(或使用简单的可可应用程序)实现相同的功能?

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. 你可以使用终端中的默认方式来使用它,不要忘记使用killall SystemUIServer或重启/注销和登录。

# 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. 所以只需移动一次你想要隐藏在dontAutoLoad数组中的那些,以及你在menuExtras数组中看不到的那些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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