Start internet sharing... using applescript ?

I have the following code, and it is working…


tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preferences.sharing"
end tell

Is there a way to start internet sharing using applescript all the way ?
Using UNIX commands would be even better, if you know how…

Thanks !

I think you’ll need to employ Apple’s new GUI scripting commands in order to achieve this. (via AppleScript atleast. I don’t know of a Unix alternative.)

The code below toggles the internet sharing state. You should be able to get all you need from this:

tell application "System Preferences"
	activate
end tell

tell application "System Events"
	tell process "System Preferences"
		click menu item "Sharing" of menu "View" of menu bar 1
		tell window "Sharing"
			tell tab group 1
				click radio button "Internet"
				if (exists button "Stop") then
					click button "Stop"
				else if (exists button "Start") then
					click button "Start"
				end if
			end tell
		end tell
	end tell
end tell

Remember, this requires the new “System Events” application available here:
http://a816.g.akamai.net/7/816/51/bcc5d74bb2a53c/www.apple.com/applescript/GUI/UIscriptingbeta.sit

thanks a lot for the reply !

I’ll test that code for sure :smiley:

I’m a newby, but I cut and pasted both those scripts to my script editor, ran them and got an error. Can anyone help me? Gizmo, did this work for you?:frowning:

It didn’t work.

While Script Editor 2 is quite an improvement over previous versions, I don’t think that GUI scripts require it. :slight_smile:

good old routing isn’t too tough in Unix. Really, you have to run the following commands to get it running in the terminal (run them in sudo or as root):

           natd -interface xxx  

the xxx is the interface you want to share (en0 for enet, en1 for airport, ppp0 for modem)

then run

            /sbin/ipfw -f flush
            /sbin/ipfw add divert natd all from any to any via xxx
            /sbin/ipfw add pass all from any to any

again, xxx is the same interface as from above.

If you need more help with it, go into a terminal and type “man natd”

:rolleyes: Hmmm… Not quite there. The applescript above doesn’t seem to completely run. In fact it doesn’t select the internet tab. It seems like a timing problem as the script will work if you manually open the sharing pane and then run the script. If you run the script with system prefs closed, it turns off file sharing. Any thoughts? I really want internet sharing to start on system startup.

yeah, i tried for hours yesterday sticking in delays here and there and varying the times, but no success…finally i just put it in a script folder and gave up. :cry:

Hey, what about a startup script that will run the scripts in a script folder…hmmmm…that would definatley work (a work around atleast!)

alfeo