如何使用AppleScript访问隐私选项卡下的辅助功能页并输出应用列表
修正后实现代码
你原来的代码存在语法结构错误、缺少页面跳转逻辑、未调用正确的UI读取API三个问题,修改后可直接在终端运行的命令如下:
osascript -e 'tell application "System Preferences" activate set current pane to pane id "com.apple.preference.security" reveal anchor "Privacy_Accessibility" of current pane delay 0.5 tell application "System Events" tell table 1 of scroll area 1 of group 1 of tab group 1 of window "安全性与隐私" of application process "System Preferences" set appList to value of static text 1 of every row where value of static text 1 is not missing value end tell end tell quit return appList end tell'
注意事项
- 运行前需要先给当前使用的终端应用开启「辅助功能」权限,否则会触发权限错误无法读取列表,权限开启路径:系统偏好设置>安全性与隐私>隐私>辅助功能,勾选对应终端即可
- 若你的系统为英文语言环境,需将代码中的窗口名
"安全性与隐私"替换为"Security & Privacy" - 代码中加入了0.5秒的等待时长,避免系统偏好设置页面未加载完成导致读取失败,若你的设备性能较差可适当调大该数值
内容的提问来源于stack exchange,提问作者Georgy
相关产品推荐
相关产品推荐

