Mac OS X下全局代理很好用,但是需要切换的时候就比较麻烦了,需要网络偏好设置–高级–代理这些菜单一级一级点进去,利用脚本来实现代理切换,就会方便很多.
脚本主要利用系统中的networksetup这个工具,在终端中输入以下命令
networksetup -commands
就可以看到命令指南,利用这些命令可以实现很多功能,不仅仅是代理的设置与切换
这里我设置socks代理,自动代理,以及关闭代理的切换,同时通过Growl来通知:
-- Switch Proxy
-- Author: ep
-- MAC OS Version: OSX/SnowLeopard
-- Date: 10/31/2010
tell application "Finder"
set proxy_dialog to display dialog "Switch Proxy. Select Interface:" buttons {"All On", "Auto Proxy", "All Off"} default button "All On" with title "Switch Proxy" giving up after 5
set proxy_interface to button returned of proxy_dialog
end tell
tell application "GrowlHelperApp"
set the allNotificationsList to {"Switch Proxy"}
set the enabledNotificationsList to {"Switch Proxy"}
register as application "Switch Proxy" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Script Editor"
end tell
if proxy_interface is "All On" then
do shell script "networksetup -setsocksfirewallproxy AirPort 127.0.0.1 7070"
do shell script "networksetup -setsocksfirewallproxystate AirPort on"
do shell script "networksetup -setautoproxystate AirPort off"
tell application "GrowlHelperApp"
notify with name "Switch Proxy" title "Proxy All On" description "Switch Proxy All On." application name "Switch Proxy"
end tell
end if
if proxy_interface is "Auto Proxy" then
do shell script "networksetup -setautoproxyurl AirPort file://localhost/Users/ep/Documents/autoproxy.pac"
do shell script "networksetup -setautoproxystate AirPort on"
do shell script "networksetup -setsocksfirewallproxystate AirPort off"
tell application "GrowlHelperApp"
notify with name "Switch Proxy" title "Auto Proxy On" description "Switch Auto Proxy On." application name "Switch Proxy"
end tell
end if
if proxy_interface is "All Off" then
do shell script "networksetup -setsocksfirewallproxystate AirPort off"
do shell script "networksetup -setautoproxystate AirPort off"
tell application "GrowlHelperApp"
notify with name "Switch Proxy" title "Proxy All Off" description "Switch Proxy All Off." application name "Switch Proxy"
end tell
end if
Country Name (2 letter code) [AU]://输入国家简写
State or Province Name (full name) [Some-State]: //省市
Locality Name (eg, city) []: //城市
Organization Name (eg, company) [Internet Widgits Pty Ltd]: //组织名称或公司名称
Organizational Unit Name (eg, section) []: //可以不用填
Common Name (eg, YOUR name) []: //输入要配置ssl的域名,因我的是wildcard ssl,所以我写*.epis.me
Email Address []: //输入邮箱,和域名的whois里邮箱一致