如何仅在选中时取消选中菜单栏选项
How to uncheck menu bar option only if checked
我目前正在尝试编写一个脚本来隐藏工具栏以获得最佳的全屏显示效果。问题是我无法设法只在必要时隐藏工具栏,所以如果工具栏已经从以前的脚本使用中隐藏,它会再次显示工具栏。这是代码的一部分。
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
if menu item "Hide Status Bar" of menu "View" of menu bar 1 exists then
click menu item "Hide Status Bar" of menu "View" of menu bar 1
end if
if menu item "Hide Favorites Bar" of menu "View" of menu bar 1 exists then
click menu item "Hide Favorites Bar" of menu "View" of menu bar 1
end if
if menu item "Hide Tab Bar" of menu "View" of menu bar 1 exists then
click menu item "Hide Tab Bar" of menu "View" of menu bar 1
end if
if menu item "Always Show Toolbar in Full Screen" of menu "View" of menu bar 1 exists then
click menu item "Always Show Toolbar in Full Screen" of menu "View" of menu bar 1
end if
end tell
end tell
有人能帮忙吗?我在系统偏好设置中看到一些关于实际复选框的内容,但这并不完全有效...
假设 Safari,根据问题上的 safari
标签,并且只会点击 Always Show Toolbar in Full Screen menu item当它处于Full Screen视图时,那么下面的example AppleScript code 会做到这一点。
示例 AppleScript 代码:
tell application "System Events"
tell application process "Safari"
tell its menu "View" of menu bar 1
if exists menu item "Always Show Toolbar in Full Screen" then
if the value of attribute "AXMenuItemMarkChar" of ¬
menu item "Always Show Toolbar in Full Screen" is "✓" then
click menu item "Always Show Toolbar in Full Screen"
end if
end if
end tell
end tell
end tell
由于目标 菜单项 也存在于正常的 window 中,尽管未启用,这是另一种方法处理它,因为它首先检查它是否已启用并且也被选中,如果是,请单击它以取消选中它:
示例 AppleScript 代码:
tell application "System Events" to ¬
tell application process "Safari" to ¬
tell its menu "View" of menu bar 1 to ¬
tell its menu item "Always Show Toolbar in Full Screen" to ¬
if the value of attribute "AXEnabled" is true and ¬
the value of attribute "AXMenuItemMarkChar" is "✓" then click it
我目前正在尝试编写一个脚本来隐藏工具栏以获得最佳的全屏显示效果。问题是我无法设法只在必要时隐藏工具栏,所以如果工具栏已经从以前的脚本使用中隐藏,它会再次显示工具栏。这是代码的一部分。
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
if menu item "Hide Status Bar" of menu "View" of menu bar 1 exists then
click menu item "Hide Status Bar" of menu "View" of menu bar 1
end if
if menu item "Hide Favorites Bar" of menu "View" of menu bar 1 exists then
click menu item "Hide Favorites Bar" of menu "View" of menu bar 1
end if
if menu item "Hide Tab Bar" of menu "View" of menu bar 1 exists then
click menu item "Hide Tab Bar" of menu "View" of menu bar 1
end if
if menu item "Always Show Toolbar in Full Screen" of menu "View" of menu bar 1 exists then
click menu item "Always Show Toolbar in Full Screen" of menu "View" of menu bar 1
end if
end tell
end tell
有人能帮忙吗?我在系统偏好设置中看到一些关于实际复选框的内容,但这并不完全有效...
假设 Safari,根据问题上的 safari
标签,并且只会点击 Always Show Toolbar in Full Screen menu item当它处于Full Screen视图时,那么下面的example AppleScript code 会做到这一点。
示例 AppleScript 代码:
tell application "System Events"
tell application process "Safari"
tell its menu "View" of menu bar 1
if exists menu item "Always Show Toolbar in Full Screen" then
if the value of attribute "AXMenuItemMarkChar" of ¬
menu item "Always Show Toolbar in Full Screen" is "✓" then
click menu item "Always Show Toolbar in Full Screen"
end if
end if
end tell
end tell
end tell
由于目标 菜单项 也存在于正常的 window 中,尽管未启用,这是另一种方法处理它,因为它首先检查它是否已启用并且也被选中,如果是,请单击它以取消选中它:
示例 AppleScript 代码:
tell application "System Events" to ¬
tell application process "Safari" to ¬
tell its menu "View" of menu bar 1 to ¬
tell its menu item "Always Show Toolbar in Full Screen" to ¬
if the value of attribute "AXEnabled" is true and ¬
the value of attribute "AXMenuItemMarkChar" is "✓" then click it