I have a preference pane installed in /Library/PreferencePanes. I want this preference pane to control an application that is running as root (it's a server). The preference pane bundle is owned by root. However, when I modify the preferences, it saves the results to ~/Library/Preferences. How do I get the results to save to /Library/Preferences instead?
Asked
Active
Viewed 415 times
1 Answers
1
Just with a quick look, it seems you'd need to use CFPreferences instead of NSUserDefaults. Also, you will need to elevate priviledges, which is a pain in the ass to do properly. Here's the guide for it, but Lion changed a lot specifically in authorization services, so there might not be a lot of extra info out there.

paxswill
- 1,200
- 9
- 13
-
Yup, I'm looking at the authorization services document and it does seem like a pain! – Raffi Khatchadourian Jan 20 '12 at 11:27
-
I'm also getting linker errors when I call the Authorization... functions. Any ideas why? – Raffi Khatchadourian Jan 20 '12 at 12:09
-
I seem to recall I ran across those as well, but I can't remember why. Here's the project (unfinished) that I was working on. I think the authorization works, it was working with 10.5 that was my hangup (I really should finish this project). https://github.com/paxswill/jenkins/tree/OS-X-Package/osx/PrefPane – paxswill Jan 24 '12 at 09:00
-
I tried doing the authentication first prior to calling the CFPreferences functions, however, the preference sync still wasn't working. Is it true that I can't use NSUserDefaults to do this? – Raffi Khatchadourian Jan 26 '12 at 19:13
-
Are you using a separate process for the authenticated calls? The essential steps are "Authenticate, create process with elevated privileges, communicate to process what you need done, elevated process exits as soon as done". On NSUserPreferences: the fifth paragraph of the docs state that NSUserPreferences will read host level preferences, but not write them. Even if NSUserPreferences supported writing to the host preferences, you would need to do the elevated privileges song and dance. – paxswill Jan 27 '12 at 13:47
-
No, I wasn't using a separate process. Looks like `NSUserDefaults` is a no-go here. – Raffi Khatchadourian Feb 29 '12 at 08:01