Search code examples
shellterminalapplescriptosascript

Terminal/Osascript: Automatically hide and show menu bar


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


Solution

  • 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