Applescript 选择安全和隐私中的项目

Applescript 选择安全和隐私中的项目,applescript,Applescript,我是AppleScript新手,我需要知道如何在Apple窗口中选择安全和隐私等选项。此外,我想选择的选项,在一个特定的顺序根据所附的图片 在步骤3之后,小程序需要输入硬编码的特定凭证,然后继续 到目前为止,我只使用以下代码打开了应用程序 tell application "System Preferences" activate end tell delay 1 tell application "System Events" tell process "System

我是AppleScript新手,我需要知道如何在Apple窗口中选择安全和隐私等选项。此外,我想选择的选项,在一个特定的顺序根据所附的图片

在步骤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

我将此作为概念证明,不建议在硬编码凭证时使用系统首选项的用户界面脚本安全和隐私隐私

下面的示例是在macOS Catalina下测试的AppleScript代码,并按照代码对我起作用,但是,可能需要调整
delay
命令的值才能在系统上正常工作

本例编写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代码仅此而已,不包含任何其他适当的错误处理。用户有责任根据需要添加任何适当的错误处理。请查看中的语句和语句。另请参见。

有趣!苹果的安全和隐私设置可能不会非常有效,如果它是脚本。。。只是说说而已!(无论如何,这并不是说这是不可能的)您在前面解释了退出/取消系统首选项的好处,以便使转换不那么刺耳。这里需要吗?似乎您最终确实希望系统首选项可见,并将其转到特定的锚定/窗格。如果系统首选项已在运行,
activate
将其带到前台,或不执行任何操作<代码>显示切换窗格(我假设从任何一个窗格开始移动)。因此,我想知道,在本例中,是否可以从
激活
启动脚本的功能位?我可能是错的。@CJK我几乎总是用
启动任何涉及系统首选项的AppleScript,如果运行…
,并在…
代码块时重复…
,原因不止一个,其中一个是您提到的,另一个是有一些带有窗格的模式表,这也可以处理这种情况。如果用户打开了一个模式表,那么在它被取消之前不会发生任何事情。当不需要实际查看正在发生的事情时,我通常也不使用
activate
,但是,这里需要GUI可见,否则
select
命令将失败。我看到了
activate
的需要。关于模态表的见解是需要记住的有用信息。谢谢你。