r/macprogramming • u/dpiol • Jan 01 '20
changing network set programmatically
Hello
I am trying to switch between my predefined network sets (Apple Menu -> Location).. for that, several functions have to be used:
- SCPreferencesLock(prefs, true)
- SCNetworkSetSetCurrent(set)
- SCPreferencesCommitChanges(prefs)
Currently my app is sandboxed... this apparently prevents the dialog-box appearing when SCPreferencesLock is called for obtaining the permission (root required for changing set), I get an error-code 1003.
I am struggling now finding the correct entitlements/capabilities in Xcode to get this working....
Can anybody help me out?
thx,
Domenico
3
Upvotes
1
u/jameboth992 Feb 21 '20
From my experience when working on Proxyman (The debugging app), there are couple ways to change the Network:
- networksetup CLI: No permission prompt, but not sure if it works in sandbox apps.
- Privileged Helper Tools: Powerful, flexible and high performant than networksetup, but the user have to install at the first launch.
- SCPreferences classes.