enabling/disabling Internet Sharing with terminal in mac osx 10.9.2

The problem is setting the internet sharing with CLI instead of GUI in Mac OS 10.9.2

I followed instructions as per this thread Start/stop internet sharing from a script? including both CLI and scripting the system pref app, but to no avail. Also tried the Sidekick app (formerly NetworkLocation) and finding that it cannot set up internet sharing on its own.

This is the situation:

  1. CLI only launches internetsharing.plist file, while other things such as bootpd and natpmpd are not launched. I tried to make a copy-bootpd.plist file permanently resident in /etc but that doesn't seem to do any better.

  2. I was already using a script originally, and the reason I switched to CLI was that GUI scripting of System Preferences is almost impossible in 10.9.2 as object names are not properly passed. Hence the same script will work or not work, depending on something I'll never find out.

  3. Sidekick is unable to do more than start and run an app, while modifying the settings within the app still needs to be done by hand.

Question: Is there someone out there who can pick every single event taking place when one checks internet sharing box in the sharing pref pane, and possibly suggest how to activate the same events with CLI?


Solution 1:

I was browsing the same thread you linked to and also found that none of the answers worked. However I was able to modify Philip Regan's solution to work with my Mac OS version (10.9.3).

Here is the modified solution.

tell application "System Preferences" to set current pane to pane "com.apple.preferences.sharing"
delay 1
tell application "System Events" to tell process "System Preferences"
    click checkbox 1 of row 8 of table 1 of scroll area 1 of group 1 of window "Sharing" -- change to row 10 if you are using anything before Snow Leopard
    delay 1
    if (exists sheet 1 of window "Sharing") then
        click button "Start" of sheet 1 of window "Sharing"
    end if
end tell
ignoring application responses
    tell application "System Preferences" to quit
end ignoring

This pertains to number 2 in your list... you might want to check out an app called "Accessibility Inspector". It was helpful in finding the new path to the particular GUI element this script modifies.