我正在尝试使用Apple脚本在系统首选项中打开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代理框,它们是高级下拉选项卡的一部分,但我不知道“路径”是什么。有人可以帮帮我吗?感谢;)
答案 0 :(得分: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
答案 1 :(得分: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"