在 El capitan 中以编程方式 'auto hide menubar'

Programmatically 'auto hide menubar' in El capitan

我真的很喜欢 El Capitan 中的 'auto hide menubar' 选项,但有时我喜欢它(私人)有时我不喜欢它(工作)。有没有办法通过更改 plist 文件中的值以编程方式 show/hide 它?如果是这样,该设置是在哪个 plist 文件中找到的?感谢任何帮助。

来自 AppKit 发行说明:

NSApplication (New since WWDC Seed)

10.11 supports a new type of menubar behavior that hides the menubar during normal non-fullscreen interaction. The menubar shows itself automatically when the mouse moves into a hot area at the top of each display. When this mode is enabled, the NSApplication.presentationOptions property will include the NSApplicationPresentationAutoHideMenuBar value.

Prior to 10.11, the SetSystemUIMode API provided by HIToolbox, and the setPresentationOptions API of NSApplication provided by AppKit, did not allow explicitly enabling an auto-hiding menubar without also hiding the Dock. -setPresentationOptions now allows the options to contain AutoHideMenuBar without also including HideDock or AutoHideDock. To ensure compatibility with existing applications, the SetSystemUIMode API will only allow applications linked on 10.11 and later to pass the combination of kUIModeNormal and kUIOptionAutoShowMenuBar; if this combination is specified by an application linked on Yosemite or earlier, the AutoShowMenuBar option is ignored

您正在寻找这个位。根据需要翻转它。

typedef NS_OPTIONS(NSUInteger, NSApplicationPresentationOptions) {
/* Flags that comprise an application's presentationOptions */
    NSApplicationPresentationAutoHideMenuBar            = (1 <<  2), 
} NS_ENUM_AVAILABLE_MAC(10_6);

Rich Trouton on apple.stackexchange.com

所回答

以下是使用默认设置隐藏和取消隐藏菜单栏的方法:

隐藏:

defaults write NSGlobalDomain _HIHideMenuBar -bool true

显示:

defaults write NSGlobalDomain _HIHideMenuBar -bool false

一旦 运行,注销并重新登录。或者,您可以 运行 作为登录用户执行以下命令以重新启动 Finder 并显示更改:

killall Finder

MacOs Sierra

正如 trevordmiller 在下面的评论中指出的那样,在 Sierra 中,您似乎必须先关闭终端才能使更改生效。

截至 10.12.5,我发现 @trevordmiller 仅部分正确;每个应用程序似乎都需要单独重新启动才能注册新设置。换句话说,如果我使用:

defaults write NSGlobalDomain _HIHideMenuBar -bool false
killall Finder

这仅在 Finder 处于活动状态时显示菜单栏。要在其他应用程序中显示它,我必须重新启动它们。 Killall Finder 除了重新启动 Finder 应用程序并为其注册设置外,其他任何方式都不需要。重启任何终端应用程序也是如此。

来不及了。如果它对其他人有帮助,可以使用快捷方式。

打开Automator -> Select 服务 -> 服务接收选定的文本 -> Select 任何应用程序中没有输入 -> 添加运行 Shell Script action -> 添加以下行。

bool=$(defaults read NSGlobalDomain _HIHideMenuBar)
if [ "$bool" == 0 ]; then
    defaults write NSGlobalDomain _HIHideMenuBar -bool true
else
    defaults write NSGlobalDomain _HIHideMenuBar -bool false
fi

保存。 (这些步骤创建了一个在系统启动时运行的服务。)

给个捷径,

转到系统偏好设置 -> 键盘 -> 快捷方式 -> Services -> 滚动到最后找到 General 部分 -> 为服务设置首选快捷方式。

❯ /usr/bin/defaults write NSGlobalDomain _HIHideMenuBar -bool [true|false]

但是您必须关闭 Finder 应用程序的实例,然后再次启动它:

# `-g` don't bring app to foreground, `-a` specify app name
❯ killall Finder && open -ga /System/Library/CoreServices/Finder.app/

作为热键触发脚本来切换它on/off (hide/unhide):

if (( `/usr/bin/defaults read NSGlobalDomain _HIHideMenuBar` == 0 ));
then
    /usr/bin/defaults write NSGlobalDomain _HIHideMenuBar -bool true \
    && killall Finder \
    && open -ga /System/Library/CoreServices/Finder.app/
else
    /usr/bin/defaults write NSGlobalDomain _HIHideMenuBar -bool false \
    && killall Finder \
    && open -ga /System/Library/CoreServices/Finder.app/
fi
  • can be used with Alfred workflows, Hammerspoon, Keyboard maestro, Automator, etc.