我没有Wi-Fi路由器,所以当我在家里的时候,我需要把我的笔记本电脑变成Wi-Fi信号源,这样我和我的伴侣都可以接入互联网。
然而,白天我在咖啡馆工作,需要使用他们的Wi-Fi。
我正在运行Snow Leopard,我发现不断地关闭和打开,首先是互联网共享,然后是Wi-Fi,实在是太麻烦了。
有没有快速解决AppleScript问题的好主意?
发布于 2010-04-25 03:27:11
您可以使用launchctl以编程方式启动或停止互联网共享服务。
以下AppleScript将启动互联网共享:
do shell script "/bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
以下AppleScript将停止互联网共享:
do shell script "/bin/launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
发布于 2011-01-04 08:32:08
我正在使用Automator中的这个AppleScript,这样我就可以轻松地将其作为服务使用,并为其提供键盘快捷键。
切换互联网共享:
register_growl()
try
if isRunning("InternetSharing") then
do shell script "launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
if isRunning("InternetSharing") then
error "Internet Connection Sharing was Not Disabled"
else
my growlnote("Success", "Internet Connection Sharing Disabled")
end if
else
do shell script "launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
if isRunning("InternetSharing") then
my growlnote("Success", "Internet Connection Sharing Enabled")
else
error "Internet Connection Sharing was Not Enabled"
end if
end if
on error errMsg
my growlnote("Error", errMsg)
end try
on isRunning(processName)
try
return 0 < length of (do shell script "ps ax | grep -v grep | grep " & processName)
on error
return false
end try
end isRunning
on register_growl()
try
tell application "GrowlHelperApp"
set the notificationsList to {"Success", "Warning", "Error"}
register as application "Toggle Internet Connection Sharing" all notifications notificationsList default notifications notificationsList icon of application "Sharing"
end tell
end try
end register_growl
on growlnote(growltype, str)
try
tell application "GrowlHelperApp"
notify with name growltype title growltype description str application name "Toggle Internet Connection Sharing"
end tell
end try
end growlnote
我在苹果堆栈交换上cross-posting这个问题,因为这个问题在两个地方都被问到了。
发布于 2011-01-20 22:31:35
不确定您是否仍在寻找解决方案,但是...这是一个用于启用或禁用互联网共享的苹果脚本
tell application "System Preferences"
activate
reveal (pane id "com.apple.preferences.sharing")
end tell
tell application "System Events"
tell process "System Preferences"
try
click checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing"
if checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing" is equal to 1 then
repeat until sheet of window 1 exists
delay 0.5
end repeat
end if
if (sheet of window 1 exists) then
click button "Start" of sheet of window 1
end if
tell application "System Preferences" to quit
activate (display dialog "Internet Sharing preferences sucessfully flipped")
on error
activate
display dialog "something went wrong in automation but you are probably in the right menu..."
return false
end try
end tell
end tell
我也会在苹果堆栈交换帖子上发表这篇文章。
https://stackoverflow.com/questions/2704889
复制相似问题