Toggling the Autohide Menu Bar Setting on macOS Big Sur

This is super easy now! A commenter updated me with this Stack Overflow post, it's now as easy as flipping a preference. Yay!

tell application "System Events"
tell dock preferences to set autohide menu bar to not autohide menu bar
end tell
6 Likes

@jldeen thanks a lot for sharing the AppleScript :+1:
It can be so simple after all :wink:

2 Likes

Thank you so much!

When did Apple fix this?

I wish I knew - the Stack Overflow comment is from December 2020, but they didn't update their docs or KB articles as far as I could tell.

BEST NEWS of 2021!

1 Like

Agree. Huge win!

1 Like

Another somewhat simplified version of this AppleScript, which will allow for toggling between the two states.

Autohide On:

tell application "System Events"
tell dock preferences to set autohide menu bar to true
end tell

Autohide Off:

tell application "System Events"
tell dock preferences to set autohide menu bar to false
end tell
3 Likes

This is great. I’ve made a gist of a shell script which will let you easily show the current status, set a specific status, or toggle visibility.

Sure, but I think the easier solution is to start off with a known visibility state represented by a boolean, and then whenever you switch it, toggle the boolean.

That’s what I do now, after a lot of experimentation.

I don't have Big Sur to test with, but this will probably work.

tell application "System Events"
   tell dock preferences
      set autohide menu bar to not (autohide menu bar)
   end tell
end tell

-Chris

1 Like

You are correct. That does toggle visibility on/off.

Very clever!

2 Likes

Works on Big Sur for me. Setting autohide on/off - line 4 - hides dock too.

tell application "System Events"
	tell dock preferences
		set autohide menu bar to not (autohide menu bar)
		set autohide to not (autohide)
	end tell
end tell

-leland

2 Likes

I tried the script and it works perfectly fine.
However on Mac OS Monterey there's a new option to turn autohide for the menu bar on/off for full screen apps:

This is actually a really cool feature - especially on the new MacBook Pros with THE NOTCH because this way the space left and right from the notch is not only black when using fullscreen apps, but it's actually used for the menu (white letters on black background)

Now the bummer is, that i.e. when watching a video (i.e. YouTube) in fullscreen mode, it still shows the menu above the video when I actually would like to hide it.

Long story short, how do I need to alter the above mentioned script to toggle the second option "autohide menu bar in full screen" in the dock preferences?

Help is greatly appreciated!

I’ll look at this when I get a chance.

1 Like

I’m not sure I understand the problem. I have “the notch” on the M1, and tried the full screen checkbox both on and off in full screen (when using Preview), and don’t see a difference. The menubar is hidden in both cases.

You would've to quit and restart Preview for the change to take effect.

Here's an example using Safari:

First with autohide checkbox checked:

In the second example the "autohide in full screen" checkbox is unchecked:

Now when watching a video on YouTube in full screen mode, the menu remains present:

you know what I mean?

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Preferences"
	activate
	reveal pane id "com.apple.preference.dock"
	delay 1
	tell application "System Events"
		tell application process "System Preferences"
			tell window "Dock & Menu Bar"
				set checkboxlist to every checkbox
				repeat with acheckbox in checkboxlist
					display dialog "Name:  " & name of acheckbox
					display dialog "Value:   " & value of acheckbox
				end repeat
				(*
				set theCheckBox to (checkbox "Automatically hide and show the menu bar")
				tell theCheckBox
					if its value = 0 then
						click
					end if
				end tell
				*)
			end tell
		end tell
	end tell
	quit
end tell

Thanks so much ikenassi.
I'm a total newbie to apple scripts.
So your script told me the name of the checkbox is "automatically hide and show the menu bar in full screen"

I took the part you put in brackets and altered it slightly with what I thought could make sense. It now indeed does the job. The only thing is that when running the script, of course the preference window pops up or a second or two - is there a way I could avoid that?
I mean if not that's already been a huge help!

That's the script I used now:

use scripting additions

tell application "System Preferences"
	activate
	reveal pane id "com.apple.preference.dock"
	delay 1
	
	tell application "System Events"
		tell application process "System Preferences"
			tell window "Dock & Menu Bar"
				set theCheckBox to (checkbox "Automatically hide and show the menu bar in full screen")
				tell theCheckBox
					if its value = 0 then
						click
					else
						click
					end if
				end tell
			end tell
		end tell
	end tell
	quit
end tell

Note: When posting blocks of code to the forums, use three "back-tick" characters: ` on the line BEFORE and AFTER the code block and you will get:

a nicely formatted 
       code block
            like this

Here is an example using the code from a previous message:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Preferences"
	activate
	reveal pane id "com.apple.preference.dock"
	delay 1

	tell application "System Events"
		tell application process "System Preferences"
			tell window "Dock & Menu Bar"
				set theCheckBox to (checkbox "Automatically hide and show the menu bar in full screen")
				tell theCheckBox
					if its value = 0 then
						click
					else
						click
					end if
				end tell
			end tell
		end tell
	end tell
	quit
end tell


1 Like

Tested on macOS Monterey, give this AppleScript a try:

tell application "System Preferences"
	reveal pane id "com.apple.preference.dock"
end tell
delay 0.5
tell application "System Events" to tell process "System Preferences" to tell window "Dock & Menu Bar"
	click checkbox "Automatically hide and show the menu bar on desktop"
end tell
delay 0.5
quit application "System Preferences"

Alfred Workflow over here:

1 Like