How does one programmatically change proxy settings on a mac osx. I am fluent in ios, and since mac os programming is similar there shouldn't be much problems with it. However I lack the logic needed to create proxy changes programmatically.. Manual tweaking is extremely easy. This is the network tab in System Preferences I am after:
What I have tried:
let dynamicStore: SCDynamicStoreRef = SCDynamicStoreCreate(nil, "setProxy" as CFString, nil, nil)!
let updated = SCDynamicStoreSetValue(dynamicStore, "HTTPProxy" as CFStringRef, "111.222.333.1") // updated is false, indicating unsuccessful operation
Also tried this, but the dictionary returned is read only
let dynamicStore: SCDynamicStoreRef = SCDynamicStoreCreate(nil, "myFunc" as
CFString, nil, nil)!
let proxyDict = SCDynamicStoreCopyProxies(dynamicStore)
if let proxyDict = SCDynamicStoreCopyProxies(dynamicStore) as NSDictionary? {
if let port = proxyDict["HTTPPort"] as? Int {
print("HTTPPort:", port)
proxyDict["HTTPPort"] = 8088; // can't do that
}
}
I am running out of ideas.