Terminal/Osascript: Automatically hide and show menu bar

1k Views Asked by At

Is there a way to enable "Automatically hide and show menu bar" checkbox via applscript/osascript or just terminal?

Current OS: macOS Mojave 10.14

I read things like LSUIPresentationMode and tried different things with osascript already

3

There are 3 best solutions below

3
On BEST ANSWER

This AppleScript code should work for you

if application "System Preferences" is running then quit application "System Preferences"
repeat until application "System Preferences" is not running
    delay 0.1
end repeat
tell application "System Preferences" to reveal pane id "com.apple.preference.general"

tell application "System Events" to tell process "System Preferences" to tell window "General"
    repeat while not (exists of checkbox "Automatically hide and show the menu bar")
        delay 0.1
    end repeat
    click checkbox "Automatically hide and show the menu bar"
end tell

quit application "System Preferences"


As per the request from a comment to my answer for the original post, this following code is a conversion from AppleScript to shell script… and can be run in the Terminal.app and should produce the same results

printf 'aWYgYXBwbGljYXRpb24gIlN5c3RlbSBQcmVmZXJlbmNlc
yIgaXMgcnVubmluZyB0aGVuIHF1aXQgYXBwbGljYXRpb24gIlN5c3RlbSBQcmVmZ
XJlbmNlcyIKcmVwZWF0IHVudGlsIGFwcGxpY2F0aW9uICJTeXN0ZW0gUHJlZmVyZ
W5jZXMiIGlzIG5vdCBydW5uaW5nCiAgICBkZWxheSAwLjEKZW5kIHJlcGVhdAp0Z
WxsIGFwcGxpY2F0aW9uICJTeXN0ZW0gUHJlZmVyZW5jZXMiIHRvIHJldmVhbCBw
YW5lIGlkICJjb20uYXBwbGUucHJlZmVyZW5jZS5nZW5lcmFsIgoKdGVsbCBhcHBsa
WNhdGlvbiAiU3lzdGVtIEV2ZW50cyIgdG8gdGVsbCBwcm9jZXNzICJTeXN0ZW0gUH
JlZmVyZW5jZXMiIHRvIHRlbGwgd2luZG93ICJHZW5lcmFsIgogICAgcmVwZWF0IH
doaWxlIG5vdCAoZXhpc3RzIG9mIGNoZWNrYm94ICJBdXRvbWF0aWNhbGx5IGhp
ZGUgYW5kIHNob3cgdGhlIG1lbnUgYmFyIikKICAgICAgICBkZWxheSAwLjEKICAgI
GVuZCByZXBlYXQKICAgIGNsaWNrIGNoZWNrYm94ICJBdXRvbWF0aWNhbGx5IG
hpZGUgYW5kIHNob3cgdGhlIG1lbnUgYmFyIgplbmQgdGVsbAoKcXVpdCBhcHBsa
WNhdGlvbiAiU3lzdGVtIFByZWZlcmVuY2VzIiA='|base64 -D|osascript
3
On

Code can be shorter on "MacOS Catalina" @2019-12 with "AppleScript Editor"

tell application "System Preferences" to reveal pane id "com.apple.preference.general"

    tell application "System Events" to tell process "System Preferences" to tell window "General"
        click checkbox "Automatically hide and show the menu bar"
    end tell

quit application "System Preferences"

and you can run it from command line direct

printf 'tell application "System Preferences" to reveal pane id "com.apple.preference.general"\n tell application "System Events" to tell process "System Preferences" to tell window "General"\n click checkbox "Automatically hide and show the menu bar"\n end tell\n quit application "System Preferences"' | osascript

or from file

osascript {{script_name}}.scpt

thx @wch1zpink

https://stackoverflow.com/a/53437866/1347601

0
On

If anyone is trying to do this in Monterey, I was able to modify the terminal command from @wch1zpink, and it works great.

printf 'tell application "System Preferences" to reveal pane id "com.apple.preference.dock"\n tell application "System Events" to tell process "System Preferences" to tell window "Dock & Menu Bar"\n click checkbox "Automatically hide and show the menu bar in full screen"\n end tell\n quit application "System Preferences"' | osascript