我将其作为概念证明 ,并且不建议系统偏好设置中的 UI脚本 > 安全性和隐私权> 隐私,同时对凭据进行硬编码。
下面的示例 AppleScript 代码已在 macOS Catalina 下进行了测试,但是按编码为我工作,可能需要调整delay
命令的 value 才能在您的系统上正常工作。
此示例 AppleScript 代码旨在针对脚本编辑器 复选框在完全磁盘访问中,位于:系统偏好设置> 安全和隐私> 隐私
将myUserName
和myPassword
的值从missing value
更改为实际的用户名和密码。
set myUserName to "missing value"
set myPassword to "missing value"
set nameOfRowToSelect to "Full Disk Access"
set appCheckboxToClick to "Script Editor"
if running of application "System Preferences" then
try
tell application "System Preferences" to quit
on error
do shell script "killall 'System Preferences'"
end try
end if
repeat while running of application "System Preferences" is true
delay 0.1
end repeat
tell application "System Preferences"
activate
reveal anchor "Privacy" of pane "com.apple.preference.security"
end tell
tell application "System Events" to tell application process "System Preferences"
repeat while not (exists window "Security & Privacy")
delay 0.1
end repeat
tell window "Security & Privacy"
keystroke "f" using command down
keystroke tab
delay 0.25
select (first row ¬
of table 1 ¬
of scroll area 1 ¬
of tab group 1 ¬
whose value ¬
of static text ¬
of UI element 1 ¬
contains nameOfRowToSelect)
delay 0.25
click button "Click the lock to make changes."
repeat until exists sheet 1
delay 0.1
end repeat
delay 0.25
tell sheet 1
set value of text field 2 to myUserName
set value of text field 1 to myPassword
delay 0.25
click button "Unlock"
delay 2
end tell
click checkbox 1 ¬
of UI element 1 ¬
of (first row ¬
of table 1 ¬
of scroll area 1 ¬
of group 1 ¬
of tab group 1 ¬
whose (value ¬
of static text ¬
of item 1 ¬
of UI element 1) ¬
contains appCheckboxToClick)
repeat until exists sheet 1
delay 0.1
end repeat
delay 0.25
click button "Later" of sheet 1
delay 0.25
click button "Click the lock to prevent further changes."
delay 0.5
end tell
end tell
quit application "System Preferences"
注意:示例 AppleScript 代码就是这样,并且不包含任何其他 error 适当处理。用户有责任添加适当的,需要的或想要的任何错误处理。看看try中的error 声明和AppleScript Language Guide 声明。另请参见Working with Errors。
本文链接:https://www.f2er.com/3123229.html