终端/脚本:自动隐藏和显示菜单栏

时间:2018-11-22 09:36:16

标签: shell terminal applescript osascript

是否可以通过applscript / osascript或仅在终端上启用“自动隐藏和显示菜单栏”复选框?

当前操作系统:macOS Mojave 10.14

我已经阅读了LSUIPresentationMode之类的内容,并已经使用osascript尝试过其他操作

2 个答案:

答案 0 :(得分:2)

此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"


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

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

答案 1 :(得分:0)

@ 2019年12月“ MacOS Catalina”上的代码可以用“ 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

thx @ wch1zpink

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