Skip to content

Instantly share code, notes, and snippets.

@jldeen
Created October 15, 2020 19:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jldeen/5f070004d1f02825900aa0bb7aa5e6e6 to your computer and use it in GitHub Desktop.
Save jldeen/5f070004d1f02825900aa0bb7aa5e6e6 to your computer and use it in GitHub Desktop.
function toggleMenu () {
~/.dotfiles/bin/toggleMenuBigSur.sh
}
#!/usr/bin/env osascript
try
if application "System Preferences" is running then do shell script "killall 'System Preferences'"
end try
repeat until application "System Preferences" is not running
delay 0.1
end repeat
tell application "System Preferences"
reveal anchor "Main" of pane id "com.apple.preference.dock"
end tell
tell application "System Events" to tell application process "System Preferences"
repeat while not (exists of UI element "Automatically hide and show the menu bar" of window "Dock & Menu Bar")
delay 0.1
end repeat
click UI element "Automatically hide and show the menu bar" of window "Dock & Menu Bar"
repeat while not (exists of UI element "Automatically hide and show the menu bar" of window "Dock & Menu Bar")
delay 0.1
end repeat
end tell
try
if application "System Preferences" is running then do shell script "killall 'System Preferences'"
end try
@BrianAMartin221
Copy link

Ohh props for doing the troubleshooting for this script! I had an old one working great when the Hide Menu was in the General tab, and just updated my laptop to Big Sur. When I try to run your script in Script Editor and Keyboard Maestro I get the error

"Can't Get Anchor "Main" of pane id "com.apple.preference.dock"

If I understand right the anchor is the section In the pane that the checkbox is in.

When I run

"tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.dock"
get the name of every anchor of current pane
end tell"

It lists some of the anchor names and main isn't one of them. Is this still working for you perhaps a Big Sur release changed this.

@jldeen
Copy link
Author

jldeen commented Nov 14, 2020

@BrianAMartin221 - Can confirm this stopped working for me as of 11.0.1; it may have stopped working earlier, but I noticed it today. Will investigate and report back with the fix.

@BrianAMartin221
Copy link

Ugh bummer you did all the work to get it working. Glad I've only updated my personal machine and not my work ones yet.

I'll fiddle around with it today as well and if I get it working I'll reply here.

@jldeen
Copy link
Author

jldeen commented Nov 18, 2020

@BrianAMartin221 - Just checking in. Sadly, I don't have an update yet, but I do know what is causing the problem. I recorded a video of what's happening from an accessibility / UI perspective and just have to either script around it, or wait for a fix from apple. You can see the video here.

You and a few others have now reached out about this bug. Several people have some innovative workarounds that are discussed here.

I will keep checking back as I investigate this, or once Apple releases a fix.

@BrianAMartin221
Copy link

I set a reminder to comment here! I am one of the posters on that KM post. Thanks for the reply. Hopefully, this gets addressed in 11.1. I liked having sys pref. staying in the backround.

@gabrielbacha
Copy link

Ah perfect. Just what I was looking for. Exactly the same issue for me. Used to work in Catalina (under General), and now I get the same error "Can't Get Anchor "Main" of pane id "com.apple.preference.dock".

I'll keep an eye here to see when it gets resolved!

Thanks for this

@gabrielbacha
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment