用户 regulus6633 编写的此 applescript 代码非常适合在 macOS 12.1 中切换“自动隐藏和显示桌面上的菜单栏”系统首选项:
tell application "System Events"
tell dock preferences to set autohide to not autohide
end tell
有谁知道如何对“自动隐藏和全屏显示菜单栏”执行相同的操作?
与提到的Dock首选项一样不适用于菜单栏,因此您可以使用UI脚本来实现目标。
下面显示的 示例 AppleScript 代码,在 macOS Monterey 下的 脚本编辑器中进行了测试,其中 系统偏好设置中的语言和区域设置设置为 英语(美国) — 主要并且为我工作没有问题1.
示例 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
这是我编写的用于在“从不”和“仅全屏显示”之间切换隐藏菜单栏的快捷方式希望这会有所帮助!
on run {input, parameters}
## This script toggles the hide menu item setting from "Never" to "In Full Screen Only"
## Used the great UI Browser https://pfiddlesoft.com/ app (now no longer operational) to write
## confirmed to work for MacOS 14.2.1, but they are changing the control center layout quickly
## Archon Fung on December 22, 2023
##open the system settings app in background
do shell script "open -j x-apple.systempreferences:com.apple.ControlCenter-Settings.extension"
tell application "System Events"
tell application process "System Settings"
## set CurrentShowStr to "Never"
##get value of pop up button 1 of group 9 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Control Center"
delay 1
set CurrentShowStr to value of pop up button 1 of group 9 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Control Center"
if (CurrentShowStr is "Never") then
set NewShowStr to 3 ##In Full Screen Only
else
set NewShowStr to 4 ##Never
end if
tell pop up button 1 of group 9 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Control Center"
click
##need delays to allow the menu items to populate
delay 0.5
click menu item NewShowStr of menu 1
delay 0.5
end tell
end tell
end tell
quit application "System Settings"
return input
end run
非常感谢您分享这个!然而,我得到了
错误“”编号-1721
在 macOS 14.2.1 中运行此程序时