1

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

samecat
  • 335
  • 1
  • 11

3 Answers3

3

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
wch1zpink
  • 3,026
  • 1
  • 8
  • 19
  • I let it run for like 5minutes, sadly nothing happened besides opening the system preferences and general tab. Edit: I got it working, by changing the System Language to "Enlgish" (had German)... Although when i convert the Checkbox Title to the German one, it doesnt check it. I guess the primary language has to be english? Is it a bug? – samecat Nov 23 '18 at 09:37
  • Is it also possible to convert the applescript to terminal osascript? – samecat Nov 23 '18 at 09:48
  • @pr0cat I have this little utility app called AS2Shell.app which converts AppleScript to a shell script which can be run in the Terminal. I will add that conversion for you to my answer to your post – wch1zpink Nov 23 '18 at 17:08
0

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

Bruno
  • 6,623
  • 5
  • 41
  • 47
  • You cannot shorten the _code_ to the just what you've shown in the first two examples of your answer, because as shown both return the error **System Events got an error: Can’t get window "General" of process "System Preferences".** in one form or another! Do you even know **AppleScript**? – user3439894 Dec 09 '19 at 04:16
  • tha for your feedback @user3439894 - yes I can and I did - and what I share works ;-) – Bruno Dec 10 '19 at 13:42
  • You cannot shorten the code to the just what you've shown in the first two examples of your answer, because as shown both return the error **System Events got an error: Can’t get window "General" of process "System Preferences"**. in one form or another! That _code_ by itself **does not work**! – user3439894 Dec 10 '19 at 13:45
0

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
nautilus
  • 3
  • 4