Edit system preferences from cocoa

2.2k views Asked by At

Is there any way to edit system preferences programmatically using cocoa? Is there some framework required? I need to do this to change the global proxy settings. Also, my app is sandboxed. Is there any sample code on how to do this? Thanks for your help.

1

There are 1 answers

1
Ken Thomases On

You're looking for the System Configuration framework, but it's not going to be easy. I don't think it's possible for a sandboxed app, because it requires root privilege. (Just like you have to authenticate as an admin to modify settings in the Network pane of System Preferences.) See the System Configuration Programming Guidelines. Among other things, they say:

Applications that need to create or duplicate sets, or activate or deactivate services have a more complicated task. They must use the low-level configuration APIs. In addition, to develop these applications you must understand and use the System Configuration schema to interpret and build dictionaries that describe the new sets and services.

It’s also important to realize that to modify network preferences (in other words, to change the persistent store), your application must acquire root privileges. This is not a trivial task; for more information, you can read Authorization Services Programming Guide and review the code samples AuthSample and MoreAuthSample available at http://developer.apple.com/samplecode/Security/idxAuthorization-date.html.

Currently, the low-level configuration APIs are very basic and somewhat difficult to use. In fact, to perform common operations, such as creating a new set, you must combine the System Configuration APIs with I/O Kit access. In future versions of Mac OS X, the System Configuration framework may provide higher-level APIs to perform such network-configuration tasks.

It goes on to recommend the MoreSCF sample code, but it's been relegated to the legacy documentation section.