获取 osascript applescript 以取消选中系统首选项中的复选框查找器扩展

Getting osascript applescript to untick checkbox finder extensions in system preferences

我已经尝试查看许多已回答的问题,但无法解决我的具体问题,问题是告诉 applescript 查看系统偏好设置中的扩展并取消选中此复选框

我无法通过“扩展”>“添加的扩展”>“核心同步”>“Finder 扩展”来帮助 applescript 找到复选框,我不确定该怎么做。

我可以打开扩展选项卡并将复选框放在最前面,这是我的代码:

tell application "System Preferences"
    activate
    reveal (pane id "com.apple.preferences.extensions")
end tell

The checkbox im trying to untick

示例 AppleScript 代码,如下所示,在[=37= macOS Big Sur 下的 ]Script Editor 以及 System Preferences 中的 Language & Region 设置设置为 English (US) — Primary 并为我工作没有问题1.

  • 1 系统偏好设置 > 安全和隐私[= 中假定必要且适当的设置59=] > 隐私 已根据需要 set/addressed。

由于目标扩展是列表中的第一个,我编写了示例 AppleScript code 特定 checkbox。需要额外的编码才能按名称枚举和定位扩展。

示例 AppleScript 代码:

--  # Check to see if System Preferences is 
--  # running and if yes, then close it.
--  # 
--  # This is done so the script will not fail 
--  # if it is running and a modal sheet is 
--  # showing, hence the use of 'killall' 
--  # as 'quit' fails when done so, if it is.
--  #
--  # This is also done to allow default behaviors
--  # to be predictable from a clean occurrence.

if running of application "System Preferences" then
    try
        tell application "System Preferences" to quit
    on error
        do shell script "killall 'System Preferences'"
    end try
    delay 0.1
end if

--  # Make sure System Preferences is not running before
--  # opening it again. Otherwise there can be an issue
--  # when trying to reopen it while it's actually closing.

repeat while running of application "System Preferences" is true
    delay 0.1
end repeat

--  # Open to the Extensions pane in System Preferences.

tell application "System Preferences" to ¬
    reveal pane id "com.apple.preferences.extensions"

tell application "System Events"
    tell application process "System Preferences"
        --  # Wait until target UI element is available.        
        set i to 0
        repeat until ¬
            exists ¬
                checkbox 1 of ¬
                UI element 1 of ¬
                row 2 of ¬
                table 1 of ¬
                scroll area 1 of ¬
                group 1 of ¬
                window 1
            delay 0.2
            set i to i + 1
            if i ≥ 20 then return
        end repeat
        --  # Click the first checkbox.
        click ¬
            checkbox 1 of ¬
            UI element 1 of ¬
            row 2 of ¬
            table 1 of ¬
            scroll area 1 of ¬
            group 1 of ¬
            window 1
    end tell
end tell

delay 0.2

tell application "System Preferences" to quit


注意:示例 AppleScript code 就是这样,没有包含任何 错误处理 不包含任何额外的 错误处理 可能是适当的。用户有责任根据需要或需要添加任何 错误处理 。查看 try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay 命令 在适当的事件之间可能是必要的,例如delay 0.5,适当设置延迟