MacOS – Notify the system that preferences were changed

macosNetworkpreferences

I disabled SIP (How do I disable System Integrity Protection (SIP) AKA "rootless" on OS X 10.11, El Capitan?) and started editing the file /Library/Preferences/SystemConfiguration/preferences.plist

I successfully edited the entries HTTPProxy, HTTPPort, HTTPEnable and save the file. Then I checked my IP address on the web, and it doesn't change. The file is set correctly, but the system doesn't know it changed and therefore it uses the old settings. When changing settings manually, hitting Apply in the Network Tab notifies the system that preferences.plist has changed and that it must use the new settings. Same goes for turning wifi off and on. I changed the file, checked the IP (it is the same) turn wifi off/on, checked the IP and now it has changed.

How can I trigger that event of notifying the system of changes programmatically on a Mac?

Best Answer

This is the wrong way to adjust the network settings on OS X. The network is managed by configd, which reads its settings from /Library/Preferences/SystemConfiguration/preferences.plist at startup. Changes should be made via configd, so that it can update its live state, the actual network interface settings, and the preferences file all together.

I know of three ways of doing this: via the Network pane in System Preferences, with the networksetup command, and with the scutil command. scutil is messy, so I don't recommend it; fortunately networksetup is easy to use. Something like this should work:

sudo networksetup -setwebproxy Ethernet proxyserver.example.com 80 off

Note that "Ethernet" is the user-friendly name of the network service (/interface); use networksetup -listallnetworkservices for a list. Also, the "off" argument means that proxy authentication is off. See the networksetup man page for more info.

BTW, please turn SIP back off. You do not need to turn it off in order to change the network settings.