Programmatically configure proxy settings on OS X

Im trying to configure proxies programmatically on OS X 10.10. scutil --proxy shows the correct settings, and the system actually uses them, but new settings are not displayed on the proxy tab in the network settings (in System Preferences).

 SCDynamicStoreRef dynamicStore = SCDynamicStoreCreate(NULL, CFSTR(APP_NAME), NULL, NULL);
 CFDictionaryRef ipv4key = SCDynamicStoreCopyValue(dynamicStore, CFSTR("State:/Network/Global/IPv4"));
 CFStringRef primaryServiceId = CFDictionaryGetValue(ipv4key,  CFSTR("PrimaryService"));
 CFStringRef primaryServicePath = CFStringCreateWithFormat(NULL, NULL, CFSTR("Setup:/Network/Service/%@/Proxies"), primaryServiceId);
 CFDictionaryRef proxySettings = SCDynamicStoreCopyValue(dynamicStore, primaryServicePath);
 //clone currnt values for update new values
 CFMutableDictionaryRef mutableProxySettings = CFDictionaryCreateMutableCopy(NULL, 0, proxySettings);

then for every value i do CFStringRef host = ...;

 CFDictionaryReplaceValue(mutableProxySettings, kSCPropNetProxiesHTTPProxy, host);

Then

 Boolean success = SCDynamicStoreSetValue(dynamicStore, primaryServicePath, mutableProxySettings);

Settings are updated, but not displayed on the proxy tab. How to make them appear there?

+4
source share

All Articles