0

我正在尝试使用苹果脚本在系统偏好设置中打开 2 个代理(我必须使用它来访问此站点),但我无法让脚本单击复选框。代码如下:

tell application "System Preferences" to set current pane to pane "com.apple.preference.network"
tell application "System Events" to tell process "System Preferences" to tell window "Network"
    click button "Advanced…"
    delay 2
    tell TabGroup of sheet 1
        tell radio button "proxies"
            click
        end tell
    end tell
end tell

我希望代码单击代理选项卡中的 http 和 https 代理框,它们是高级向下滑动选项卡的一部分,但我不知道“路径”是什么。有人可以帮我吗?谢谢;)

4

2 回答 2

2

此示例使用 Web 代理:

 tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "Network"
    click button "Advanced…"
    delay 2
    click radio button "Proxies" of tab group 1 of sheet 1
    delay 2

    repeat until focused of table 1 of scroll area 1 of group 1 of tab group 1 of sheet 1
        keystroke tab
    end repeat

    -- Make sure you start from the top of the list
    repeat 20 times
        key code 126 -- up arrow Key
        delay 0.2
    end repeat

    set counter to 0
    repeat until (value of static text of group 1 of group 1 of tab group 1 of sheet 1 as text) contains "Web Proxy Server"
        set counter to counter + 1
        key code 125
        if counter ≥ 100 then
            display dialog "You have not entered a valid protocol name" buttons {"OK"}
            exit repeat
        end if
    end repeat

    delay 1
    click checkbox 1 of row 3 of table 1 of scroll area 1 of group 1 of tab group 1 of sheet 1

end tell
于 2012-07-02T11:55:08.910 回答
0

要决定要检查哪个框,您只需更改行号。现在它设置为切换 SOCKS 代理。

tell application "System Preferences" to activate
tell application "System Preferences" to set current pane to pane id "com.apple.preference.network"
tell application "System Events" to tell process "System Preferences" to tell window 1
    click button "Advanced…"
    click radio button "Proxies" of tab group 1 of sheet 1
    set box to checkbox 1 of row 6 of table 1 of scroll area 1 of group 1 of tab group 1 of sheet 1
    set selected of row 6 of table 1 of scroll area 1 of group 1 of tab group 1 of sheet 1 to true
    click box
    set val to the value of box as boolean
    click button "OK" of sheet 1
    click button "Apply"
end tell
tell application "System Preferences" to quit
if val is true then return "Toggled On"
if val is false then return "Toggled Off"
于 2015-03-20T14:24:45.593 回答