ControlPlane icon indicating copy to clipboard operation
ControlPlane copied to clipboard

Unable to Enable/Disable Internet Sharing in 10.11 El Capitan

Open DamiansDesign opened this issue 10 years ago • 22 comments

It seams El Capitan doesn't use com.apple.InternetSharing.plist for Internet Sharing anymore. I recently upgraded from Mavericks to El Capitan and my ControlPlane setup for toggling Internet Sharing on MacBook Pro on lid open/close, no longer works.

This is what I see in system.log:

com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Could not read path: path = /System/Library/LaunchDaemons/com.apple.InternetSharing.plist, error = 2: No such file or directory

DamiansDesign avatar Oct 10 '15 22:10 DamiansDesign

I've been looking into this and it's going to be awhile. Internet Sharing is done differently in 10.11

dustinrue avatar Oct 30 '15 15:10 dustinrue

Any updates?

EntilZha avatar Nov 13 '15 18:11 EntilZha

I haven't found a way to force the system to enable/disable Internet Sharing yet

dustinrue avatar Nov 16 '15 15:11 dustinrue

Aside from ControlPlane, is there any terminal/shell way to do it? I imagine there is a fragile way to do it with applescript. Before finding ControlPlane I had a shell script to do it plus Alfred commands, but that doesn't work anymore either

EntilZha avatar Nov 16 '15 16:11 EntilZha

If you can find an AppleScript that does it I can at least use that, but as of right now I haven’t been able to capture what calls System Preferences is using to enable/disable the service yet. With each release of OS X more and more stuff is hidden or protected better.

dustinrue avatar Nov 16 '15 16:11 dustinrue

I am trying to update/modify this script: http://stackoverflow.com/questions/2704889/how-to-start-stop-internet-sharing-using-apple-script. Never used apple script before so its slow going with debugging though

EntilZha avatar Nov 16 '15 16:11 EntilZha

This works to turn it on/off:

tell application "System Preferences"
    activate
    reveal (pane id "com.apple.preferences.sharing")
end tell

tell application "System Events" to tell process "System Preferences"
    delay 2
    repeat with r in rows of table 1 of scroll area 1 of group 1 of window "Sharing"
        if (value of static text of r as text) starts with "Internet" then
            set sharingBool to value of checkbox of r as boolean
            select r
            if sharingBool is false then click checkbox of r
            #if sharingBool is true then click checkbox of r
        end if
    end repeat
    delay 2

    if (exists sheet 1 of window "Sharing") then
        click button "Start" of sheet 1 of window "Sharing"
    end if

end tell

EntilZha avatar Nov 16 '15 17:11 EntilZha

Been using that for a couple days as an Alfred workflow I run when I get to home/work. Works fairly well, its annoying that it actually opens the interface, but not much I can do about that (unless you know how to improve it). I will probably play with the delays and try to decrease them more.

Does ControlPlane support running applescripts as actions? I didn't see anything for that

EntilZha avatar Nov 18 '15 05:11 EntilZha

Any updates on this? I'm using the Applescript now but it would be awesome if it works like it should.

@EntilZha thanks! Script works great. Also, you can actually run a shell script as action in ControlPlane.

krazzer avatar Jan 14 '16 17:01 krazzer

So in theory, it would be possible to run a shell script which itself runs the Applescript? The downside of this is that a GUI would be brought up without user interaction which would be annoying (at least for me).

EntilZha avatar Jan 14 '16 17:01 EntilZha

I have yet to figure out how to enable internet sharing programmatically.

dustinrue avatar Jan 14 '16 20:01 dustinrue

Some more options here http://apple.stackexchange.com/questions/2488/start-stop-internet-sharing-from-a-script

mrjcleaver avatar Jan 15 '16 13:01 mrjcleaver

The method described in the first comment is how it works now for the older operating systems. It no longer works in 10.11.

dustinrue avatar Jan 15 '16 13:01 dustinrue

@dustinrue, is there anyway to do something low levelish like trace the system calls that the preferences application does while turning sharing on/off?

EntilZha avatar Jan 15 '16 14:01 EntilZha

I’ve never found success in doing this, but if someone can demonstrate a reliable way it’d go along ways towards getting this done.

dustinrue avatar Jan 15 '16 15:01 dustinrue

Does the interface creation method described here still work? Requires more setup, but it would work

EntilZha avatar Jan 15 '16 16:01 EntilZha

@EntilZha too much UI work to implement that to be honest. Would work as a shell script.

dustinrue avatar Jan 18 '16 20:01 dustinrue

This definitely seems like unless Apple provides a way to programmatically enable/disable internet sharing it would be hard.

I gave a shot at looking at syscall but hit a brick wall with the new System Integrity/security/above sudo thing on inspecting System Preferences. I could go and disable it in safe mode, try again, but don't have time to try that right now when an Applescript via Alfred works passably well.

EntilZha avatar Jan 18 '16 21:01 EntilZha

I'm willing to give it some effort if you show me how you were going about capturing system calls. I have safe mode disabled already for other reasons.

dustinrue avatar Jan 18 '16 21:01 dustinrue

I was trying something like this:

cd /Applications/System Preferences.app/Contents/MacOS
sudo dtruss System\ Preferences

Which gives an error about it being unreadable (this works fine with regular apps). I also tried running it, getting its PID, then doing something like strace

EntilZha avatar Jan 18 '16 21:01 EntilZha

Hi,

You can disable Internet Sharing in OS X 10.11 with a configuration profile to manage com.apple.MCX forceInternetSharingOff 1. You can find resources online for how to do that.

Alternatively, these commands appear to do the trick, too:

sudo /usr/libexec/PlistBuddy -c "Delete NAT:Enabled" /Library/Preferences/SystemConfiguration/com.apple.nat.plist
sudo /usr/libexec/PlistBuddy -c "add NAT:Enabled integer 0" /Library/Preferences/SystemConfiguration/com.apple.nat.plist

@EntilZha You can run fs_usage and grep for plist to figure out which preference files are being modified. Also see man -k dtrace for other neat tricks.

drduh avatar Feb 16 '16 18:02 drduh

I'm also using El Capitan and have this issue.

Did anyone of you find the best way to automate this via ControlPlane?

Is there a shell script available that activates the AppleScript that enables/disables Internet Sharing via the GUI -> System Preferences?

7k50 avatar Oct 29 '16 14:10 7k50