macos - 仅在选中时如何取消选中菜单栏选项
问题描述
我目前正在尝试制作一个脚本,该脚本将隐藏工具栏以获得最佳全屏效果。问题是我无法仅在必要时隐藏工具栏,因此如果工具栏已经从以前的脚本使用中隐藏,它将再次显示工具栏。这是代码的那一部分。
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 菜单项,则以下示例AppleScript代码将执行此操作。
示例 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
由于目标菜单项也存在于普通窗口中,尽管未启用,但这是处理它的另一种方法,因为它首先检查它是否已启用并被选中,如果是,请单击它以取消选中它:
示例 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
推荐阅读
- java - 到 LDAP 服务器的 Java 连接
- python - 在 Django 模型中存储矩阵
- .net - 如何在 VS 2019 中使 MongoDB/Nuget 安装可靠
- java - 如何在String java中相互交换两个字符(L和R)
- xml - 使用 openpyxl 编写值和公式?
- python - 试图在 vscode 调试控制台中执行一个scrapy FormResponse
- r - 在drc中建模多个drm模型
- symfony - 在 Symfony 中使用带有路由的片段
- javascript - 如何在 JavaScript 中创建一个填充任意数量的空数组的数组?
- mongodb - 任何人都可以在 mongodb atlas 免费访问中创建多少个集群?