Programmatically 'auto hide menubar' in El capitan
Asked Answered
R

5

5

I really love the 'auto hide menubar' option in El Capitan, but sometimes I like it (private) sometimes I don't (work). Is there a way to show/hide it programmatically by changed it's value in a plist file? If so, in which plist file is that setting found? Any help is appreciated.

Ripp answered 8/10, 2015 at 11:31 Comment(0)
R
5

As answered by Rich Trouton on apple.stackexchange.com

Here's how you can set the menubar to be hidden and unhidden using defaults:

To hide:

defaults write NSGlobalDomain _HIHideMenuBar -bool true

To show:

defaults write NSGlobalDomain _HIHideMenuBar -bool false

Once run, logout and log back in. Alternatively, you can run the following command as the logged-in user to restart Finder and show the changes:

killall Finder

MacOs Sierra

As trevordmiller points out in the comment below, in Sierra it seems you have to close your terminal first to make the change have any effect.

Ripp answered 9/10, 2015 at 14:53 Comment(4)
Any idea how to get this working in Sierra? It seems the _HIHideMenuBar has been renamed or removed as the above isn't working. I've been trying to find a list of all the NSGlobalDomain options for Sierra but haven't had any luck.Tympany
After further testing, I've confirmed that this does indeed work in Sierra, but only after the terminal is closed - killall Finder alone isn't enoughTympany
@trevordmiller That's a weird restriction by Apple. I've added your info to the answer for future reference.Ripp
@trevordmiller you've probably learned that the reason you're killing Finder is because the above preference config only applies after an app is restarted. When you restart Terminal it works; when you restart Finder it works; it works if you're okay with restarting every app where you want it to be hidden/showing. Personally, I'm better off with auto-hide and trying to find a way to programmatically activate an item on the menu bar...Emotionalize
R
5

As of 10.12.5 I am finding that @trevordmiller is only partially correct; Every application seems to need to be individually restarted to register the new setting. In other words, If I use:

defaults write NSGlobalDomain _HIHideMenuBar -bool false
killall Finder

this only shows the menu bar while Finder is active. To show it in other apps, I have to restart them. Killall Finder is not required in any way other than that it restarts Finder app and registers the setting for it. Same for restarting any terminal app.

Ritualist answered 16/7, 2017 at 23:27 Comment(0)
A
3

From AppKit release notes:

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

You are looking for this bit. Flip it as you need.

typedef NS_OPTIONS(NSUInteger, NSApplicationPresentationOptions) {
/* Flags that comprise an application's presentationOptions */
    NSApplicationPresentationAutoHideMenuBar            = (1 <<  2), 
} NS_ENUM_AVAILABLE_MAC(10_6);
Acheron answered 8/10, 2015 at 19:30 Comment(1)
Would definitely work when making apps, but I wanted to achieve this by a terminal command. Sorry, should have provided more details in the question.Ripp
I
0

Too late. If it helps someone else, a shortcut could make it handy.

Open Automator -> Select Service -> Service receives selected text -> Select no input in any application -> Add Run Shell Script action -> Add the following lines.

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

Save it. (These steps creates a service that runs whenever the system boots.)

To give a shortcut,

Go to System Preferences -> KeyBoard -> Shortcuts -> Services -> Scroll to last to find General section -> Set a preferred shortcut for the service.

Ibo answered 18/6, 2018 at 18:42 Comment(0)
A
0
❯ /usr/bin/defaults write NSGlobalDomain _HIHideMenuBar -bool [true|false]

But you'll have to close instances of the Finder application, and fire it up again:

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

As a hotkey triggered script to toggle it 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.
Alceste answered 2/9, 2021 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.