I use this AppleScript from Automator so that I can easily use it as a service and give it a keyboard shortcut.
Switch internet sharing:
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
I cross-post on the Apple exchange because the question was asked in both places.
Prestaul
source share