如何使用AppleScript将Sophos应用添加至Mac Full Disk Access列表
AppleScript实现Full Disk Access列表添加Sophos应用的解决方案
核心定位逻辑
你之前的步骤已经完成了安全偏好设置打开、隐私标签页进入、解锁操作,卡在添加按钮点击是因为Security & Privacy的UI元素层级较深,需要按系统版本精准匹配元素属性:
- macOS 12.x(Monterey)及更早版本:添加按钮名称为 Add an application,位于Full Disk Access右侧列表的下方区域
- macOS 13.x(Ventura)/14.x(Sonoma):添加按钮为带「+」标识的图标按钮,role description为 添加按钮,无需匹配名称直接通过属性定位
可用代码片段
-- 前置:确保已解锁Security & Privacy窗口且停留在Full Disk Access标签页 tell application "System Events" -- Ventura及以上版本如果系统设置名为System Settings,这里把"System Preferences"替换为"System Settings" tell process "System Preferences" set frontmost to true -- 定位并点击添加按钮 if (system version of (system info)) ≥ "13.0" then click button 1 of group 2 of scroll area 1 of group 1 of window "Security & Privacy" else click button "Add an application" of scroll area 1 of group 1 of window "Security & Privacy" end if delay 1 -- 调出路径跳转窗口 keystroke "g" using {shift down, command down} delay 0.5 -- 输入需要添加的Sophos应用路径,可替换为你需要的目标路径 keystroke "/Applications/Sophos/Sophos Endpoint.app" delay 0.5 keystroke return delay 0.5 -- 点击确认添加 click button "Open" of window "Open" delay 1 end tell end tell
批量添加多路径处理
如果需要添加/Library/下多个Sophos相关组件,可把所有路径存为列表循环执行:
- 定义路径列表:
set sophosPathList to {"/Applications/Sophos/Sophos Endpoint.app", "/Library/Sophos Anti-Virus/SophosScanD", "/Library/Sophos Anti-Virus/SophosServiceManager"} - 每次循环添加后等待2秒,确保UI完全响应再执行下一次操作,避免元素定位失败
注意事项
- 运行该脚本的载体(脚本编辑器、终端、MDM工具等)需要提前被赋予辅助功能权限,否则System Events无法操作系统UI元素
- 中文系统下按钮名称可能会变为本地化名称,把代码中的"Add an application"、"Open"替换为对应的中文"添加应用"、"打开"即可
- 提前校验所有添加路径的有效性,避免因路径不存在导致脚本卡住
内容的提问来源于stack exchange,提问作者NathanGuidry
相关产品推荐
相关产品推荐

