检测在“安全和隐私”选项卡中选择了哪个锚点

问题描述 投票:0回答:1

我目前正在尝试检测在“安全和隐私”的“隐私”窗格中选择了哪个“锚点”。使用以下代码,我可以获得所有可用锚点的列表,但我不知道如何提取当前选定的锚点:

tell application "System Preferences"
    activate
    get the name of every anchor of current pane
end tell

结果:

{"Privacy_Microphone", "Privacy_Reminders", "Privacy_Calendars", "Firewall", "Privacy_Assistive", "Privacy_LocationServices", "Privacy_Contacts", "General", "Advanced", "Privacy_Accessibility", "Privacy_Camera", "Privacy_SystemServices", "FDE", "Privacy", "Privacy_AllFiles"}

现在我正在尝试检测是否选择了辅助功能(

Privacy_Accessibility
)锚点。我尝试过查看大约 20 个相关的 SO 问题,但是它们都没有提供 currently selected 元素的解决方案。

非常感谢

macos applescript
1个回答
0
投票

“系统偏好设置”应用程序的直接脚本编写能力较弱。因此,您经常不得不使用 GUI 脚本,这是不可取的。

您真的需要知道选择了哪个锚点吗?揭示你需要的锚点可能会更好。在这种情况下,不需要 GUI 脚本。

无论如何,这是 Catalina 操作系统的 GUI 脚本解决方案,它给出了所选锚点的名称:

tell application "System Preferences" to activate

tell application "System Events" to tell process "System Preferences"
    tell window 1 to tell tab group 1 to tell scroll area 1 to tell table 1
        set aName to name of UI element 1 of (get 1st row whose selected is true)
    end tell
end tell
© www.soinside.com 2019 - 2024. All rights reserved.