Open DamiansDesign opened 8 years ago
I've been looking into this and it's going to be awhile. Internet Sharing is done differently in 10.11
Any updates?
I haven't found a way to force the system to enable/disable Internet Sharing yet
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
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.
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
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
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
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.
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).
I have yet to figure out how to enable internet sharing programmatically.
Some more options here http://apple.stackexchange.com/questions/2488/start-stop-internet-sharing-from-a-script
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, is there anyway to do something low levelish like trace the system calls that the preferences application does while turning sharing on/off?
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.
Does the interface creation method described here still work? Requires more setup, but it would work
@EntilZha too much UI work to implement that to be honest. Would work as a shell script.
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.
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.
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
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.
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?
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