“几键式”打开或关闭Mac OS的Internet 共享

Macbook提供了非常简单易用的Internet共享功能,可以做为一个轻量级的家庭无线路由使用。只要你的mbp能够上网,那么你的手机、touch和pad的设备就都可以通过wifi共享mbp的网络,实现无线上网。
具体设置非常简单,系统偏好设置->共享->Inernet共享->启动几个步骤,但是每次点这么几下,还是很麻烦,我们通过Apple Script和QS这个神器可以让简单的操作更简单。

打开AppleScript编辑器,键入如下代码(供参考):

以下代码请根据上图缩进。

tell application “System Preferences”
activate
end tell

tell application “System Events”
tell process “System Preferences”
click menu item “共享” of menu “显示” of menu bar 1
delay 2
tell window “共享”
click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1
delay 1
if (exists sheet 1) then
if (exists button “打开 AirPort” of sheet 1) then
click button “打开 AirPort” of sheet 1
delay 1
end if
click button “启动” of sheet 1
else
do shell script “/usr/sbin/networksetup -setairportpower en1 off”
delay 1
end if
end tell
end tell
end tell

ignoring application responses
tell application “System Preferences” to quit
end ignoring

文件->存储,保存为脚本文件,例如ws.scpt,然后运行,效果看到了吧。
之后呼出QS,如果你是mac使用者而不知道QS,那么就用Google百度一下。在QS中通过路径方式找到ws.scpt,运行之。运行一次之后就可以直接通过键盘操作了。呼出QS,键入ws,应该就可以找到ws.scpt,然后敲回车键,搞定。

好了,这下呼出QS,键入ws和回车,就能自动开启或关闭Internet共享了。

posted @ 2011-05-09 22:24  池建强  阅读(3787)  评论(0编辑  收藏  举报