使用 applescript 隐藏全屏应用程序的菜单栏

hide menu bar for full screen apps with applescript

用户 regulus6633 的这段 applescript 代码非常适合在 macOS 12.1 中切换“自动隐藏和显示桌面上的菜单栏”系统偏好设置:

tell application "System Events"
    tell dock preferences to set autohide to not autohide
end tell

有谁知道如何对“全屏自动隐藏和显示菜单栏”做同样的事情吗?

与提到的 Dock preference 一样不适用于 Menu Bar因此,您可以使用 UI 脚本 来实现目标。

示例 AppleScript 代码,如下所示,在[=22= macOS Monterey 下的 ]Script Editor 以及 System Preferences 中的 Language & Region 设置到 英语(美国)— 小学 并为我工作没有问题1.

  • 1 系统偏好设置 > 安全与隐私[=] 中假定必要且适当的设置40=] > 隐私 已根据需要 set/addressed。

示例 AppleScript 代码:

--  # Check to see if System Preferences is 
--  # running and if yes, then close it.
--  # 
--  # This is done so the script will not fail 
--  # if it is running and a modal sheet is 
--  # showing, hence the use of 'killall' 
--  # as 'quit' fails when done so, if it is.
--  #
--  # This is also done to allow default behaviors
--  # to be predictable from a clean occurrence.

if running of application "System Preferences" then
    try
        tell application "System Preferences" to quit
    on error
        do shell script "killall 'System Preferences'"
    end try
    delay 0.1
end if

--  # Make sure System Preferences is not running before
--  # opening it again. Otherwise there can be an issue
--  # when trying to reopen it while it's actually closing.

repeat while running of application "System Preferences" is true
    delay 0.1
end repeat

--  # Open to Dock & Menu Bar

tell application "System Preferences" to ¬
    reveal pane "com.apple.preference.dock"

--  Toggle the Automatically hide and show the menu bar in full screen checkbox.

tell application "System Events"
    tell application process "System Preferences"
        tell window 1
            repeat until exists (first checkbox whose title is "Automatically hide and show the menu bar in full screen")
                delay 0.2
            end repeat
            click (first checkbox whose title is "Automatically hide and show the menu bar in full screen")
        end tell
    end tell
end tell
delay 0.2
tell application "System Preferences" to quit