10.3: Start Internet Sharing via AppleScript

Oct 27, '03 02:20:00AM

Contributed by: thefinite

I had previously submitted an AppleScript that started up Internet Sharing on a Mac, as it is will not remain on after restarts. The need remains in Panther, but the AppleScript needs to be different. I don't know if the UI Scripting Beta is still necessary, because I upgraded without a clean install. See the previous hint for more information about getting this script to work.

A pane was added to Panther verifying that you want to share your connection. This new script gets past that pane. Here is the new script:

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
      if exists sheet 1 then
        tell sheet 1
          click button "Start"
        end tell
      end if
    end tell
  end tell
end tell

ignoring application responses
  tell application "System Preferences" to quit
end ignoring
Cut and paste the above into Script Editor. If you then save it as an application and set it in your startup items, you won't have to worry about doing it manually.

Comments (12)


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