2012-07-02 20 views
0

我想用苹果脚本在系统偏好设置中打开2个代理(我必须用它来访问这个站点),但是我无法获得脚本来点击复选框。代码如下:“路径”到applescript上的代理框?

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代理盒这是在代理选项卡这是先进滑下标签的一部分,但我不知道什么是“道”是。有人能帮助我吗?感谢;)

回答

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 
+0

非常感谢!顺便说一下,你是如何获得路径的? – alexforC

+0

我使用了UI浏览器。 – adayzdone

+0

谢谢,但我仍然有一个问题.....当我更改“SOCKS代理”到“Web代理(HTTP)”并运行它,整个计算机冻结。你能否告诉我为什么和替代? – alexforC

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"