Terminal/Osascript: 自动隐藏和显示菜单栏

Terminal/Osascript: Automatically hide and show menu bar

有没有办法通过 applscript/osascript 或终端启用 "Automatically hide and show menu bar" 复选框?

当前 OS:macOS Mojave 10.14

我读过 LSUIPresentationMode 之类的东西,并且已经用 osascript 尝试过不同的东西

此 AppleScript 代码应该适合您

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"


根据评论对我对原始 post 的回答的要求,以下代码是从 AppleScript 到 shell 脚本的转换......并且可以是 运行 Terminal.app 并且应该产生相同的结果

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

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"

您可以直接从命令行 运行

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

或来自文件

osascript {{script_name}}.scpt

谢谢@wch1zpink