Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

eleven7

macrumors regular
Original poster
Mar 14, 2009
195
0
Japan
I'm attempting to write a piece of applescript to toggle internet sharing on/off.
The problem is I want to run the whole script hidden but the following code gives me an error because the 'Sharing' menu isn't accessible after I set the 'System Preference' process to false. Is there any other way I can get around this or do I just have to put up with sitting watching the script run the steps.

Code:
tell application "System Preferences"
	activate
end tell
tell application "System Events"
	set visible of process "System Preferences" to false
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
				delay 1
			end if
		end tell
	end tell
end tell

tell application "System Preferences"
	quit
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.