views:

548

answers:

2

Hi I have a background-only app that is controlled via a preference pane in the system preferences. To communicate between pref pane and app I use distributed notifications. User defaults are shared via [NSUserDefaults addSuiteNamed:]. This all works out very well.

The problem occurs when the user installs the pref pane "for all users", when prompted by the system preference pane. In this case prefs get written to ~/Library/Preferences/, same as when installed "for this user only". (I think this is the correct behavior.) However, when the prefpane reads a default key, the prefpane seems to be looking at /Library/Preferences/, not in the user's home directory.

To sum it up:

  • prefs pane installed in: ~/Library/PreferencePanes/
    • Defaults written to: ~/Library/Preferences/
    • Defaults read from: ~/Library/Preferences/
  • prefs pane installed in: /Library/PreferencePanes/
    • Defaults written to: ~/Library/Preferences/
    • Defaults read from: /Library/Preferences/

Could anyone shed some light as to where things go wrong?

Thanks, Kolja

A: 

Preference panes which get installed "for all users":

  1. Require administrator authentication (the user installing the pref pane should be prompted for an admin password)
  2. Get installed in /Library/PreferencePanes

Do both of these things occur for your pref pane? It looks like preferences should indeed be placed in ~/Library/Preferences, by example of looking at my current configuration. Therefore the correct solution (I think) is for the preference pane to be looking in your home folder's Preferences folder, not the hard disk root directory. I'm not sure how to tell the pref pane to look there, though.

Matt Ball
Yes the user gets prompted for the admin password and the prefpane is installed at /library/prefpaneAs you pointed out the questions boils down to how to tell the prefpane to look for defaults in the user directory. They get written at the correct location, just reading doesn't work.
Monobono
+2  A: 

You have essentially the same design as Growl. We use CFPreferences to read and write the user's preferences. See GrowlPreferencesController and the macros in GrowlDefinesInternal.h. The distributed notification cues both the background app and the prefpane to re-read the preferences.

(Don't take it quite as far as we do, though—it's fine to use NSNumber, NSDictionary, etc. with Core Foundation, and it's much easier to read.)

Peter Hosey
Is that header file standard C, or am I looking at Objective-C? I'm mostly curious because of all the function macros - why do people writing C (or Objective-C?) tend to do so much with function macros rather than just writing a function? I'm pretty well-versed in C but my first programming language was Java; as a consequence I find C function macros pretty sketchy. Maybe you can only speak for yourself on this one, but I am curious to hear about this from a serious developer.
Matt Ball
It's both. It adapts to whatever `#include`d or `#import`ed it. As for the macros, I don't know why the person who wrote them made them macros; they may very well be better as functions.
Peter Hosey
I was already working on source code based on growl, which I wrote two years ago. i have updated my sources to the way growl handles the stuff. The problem is prefs are still not working when the prefpane is installed for all users. Can you confirm that the growl source can handle this situation, because growl comes with an installer that doesn't leave you the choice to install the prefpane for all users.
Monobono
“growl comes with an installer that doesn't leave you the choice to install the prefpane for all users.” Yes it does. What it doesn't do is offer you the choice to install it only for yourself; that option is disabled (and I don't know why).
Peter Hosey
ok, thanks for pointing that out. I will reevaluate my code, because if the growl code does what I want, the error must be in my implementation. Thanks again.
Monobono
Update: We've since removed the install-for-only-yourself option. It caused too much confusion, especially in upgrading, as people didn't make the same choice for the upgrade as they did for the original installation and ended up with two installations.
Peter Hosey