选择安全性和隐私项

我是AppleScript的新手,我需要知道如何在Apple Window中选择选项,例如“安全性”和“隐私”。另外,我想根据所附图片按特定顺序选择选项。

在第3步之后,小程序需要放入经过硬编码的特定凭证,然后再继续。

到目前为止,我只能使用以下代码打开应用程序。

    tell application "System Preferences"
    activate
end tell
delay 1
tell application "System Events"
    tell process "System Preferences"
        click menu item "Security & Privacy" of menu "View" of menu bar 1
        delay 2
        tell window "Security & Privacy"

        end tell
    end tell
end tell
delay 2

选择安全性和隐私项

zhuoaima 回答:选择安全性和隐私项

我将其作为概念证明 ,并且不建议系统偏好设置中的 UI脚本 > 安全性和隐私权> 隐私,同时对凭据进行硬编码。

下面的示例 AppleScript 代码已在 macOS Catalina 下进行了测试,但是按编码为我工作,可能需要调整delay 命令 value 才能在您的系统上正常工作。

示例 AppleScript 代码旨在针对脚本编辑器 复选框完全磁盘访问中,位于:系统偏好设置> 安全和隐私> 隐私

myUserNamemyPasswordmissing 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

大家都在问