Use AppleScript to start Internet Sharing at startup

Jan 11, '03 11:52:00AM

Contributed by: thefinite

I have always been bothered that the Internet Sharing option must be started manually every time I restart the computer at home. I have seen other solutions for fixing this, but none that didn't require the terminal. Then I thought about trying it out with AppleScript's new UI access (download link, requires Developer Tools). It works great! Here is the text of the script (an adaptation of a sample script posted on Apple's website):

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
delay 10
tell window "Sharing"
if (exists tab group 1) then
tell tab group 1
click radio button "Internet"
delay 1
click button "Start"
delay 1
end tell
end if
end tell
end tell
end tell

ignoring application responses
tell application "System Preferences" to quit
end ignoring
Just cut and paste it into Script Editor and save it as an application. Then just make it a login item.

[Editor's note: I haven't tested this myself, but it seems much simpler than the previously posted hint. There's also another hint that may be useful...]

Comments (18)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030111085242658