Internet sharing automated

I usually rely on internet sharing for turning my mac into a Wi-Fi hotspot for connecting my iPod or my Android phone. However, it is quite cumbersome to go through System Preferences and the dialog panes if you do it quite regularly. Hints reader BrentT had this same problem and he came up with a clever applescript for turning Internet Sharing On and Off. His script did not Toggle Airport On and Off, so I added this part and I also included a quit system preferences line at the end. Here’s the script.

-- Toggle Airport Power On and Off
if (offset of "On" in (do shell script "networksetup -getairportpower en1")) > 0 then
	do shell script "networksetup -setairportpower en1 off"
	do shell script "networksetup -setairportpower en1 on"
end if

tell application "System Preferences"
end tell

tell application "System Events"
	tell process "System Preferences"
		click menu item "Sharing" of menu "View" of menu bar 1
		delay 2
		tell window "Sharing"
			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 "Turn AirPort On" of sheet 1) then
					click button "Turn AirPort On" of sheet 1
					delay 1
				end if
				click button "Start" of sheet 1
			end if
		end tell
	end tell
end tell

if application "System Preferences" is running then
	tell application "System Preferences" to quit
end if

I’ve actually converted this script into an Alfred extension, so I just hit alt+cmd and the keyword ints and the script is run.


If you liked this post please leave a comment or consider subscribing.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s