44
votes

While developing a Cocoa application on 10.9, I have noticed that if I go to ~/Library/Preferences and delete the plist file for my app (to reset it), on the next build-and-run, the app behaves as if the plist file had never been deleted at all.

It took me a long time to track down why this happens and I did not see a question/answer about it on SO, so I'm writing this question and answering it myself to help others.

4
A simple solution: restart the computer. Now delete the plist file. Now build and run, and you will be starting with clean prefs. Reason: The prefs are synchronized into memory, and are restored from memory unless you clean out memory first, which is what restarting does. - matt
Well, yea, that will do it. But rebooting your computer between each build and run is NOT a practical solution. - Bryan
No one is suggesting rebooting before each build and run - only in the special situation where you want to delete the plist file to reset it. It's a serious issue because you're fighting the system, which is keeping a secret cache of the plist file and just restores it when you delete it. - matt

4 Answers

59
votes

On 10.9, the system is doing some more robust "caching" of preferences. After deleting the plist file, I fired up Activity Monitor and force-killed the "cfprefsd" process. Be careful: there are multiple processes with this name running and you only want to kill the one running under your own user; do not kill the one running as root.

Doing this seems to flush the preferences cache and on the next run of my app, I get a pristine start-from-scratch launch.

Edit: As reported below, using defaults delete [your bundle identifier] at the command line also appears to eliminate the caching issue. I've had mixed success with this.

14
votes

I found out that killing the user process cfprefsd will reflush the cache, so your changes will be kept

killall -u $USER cfprefsd

14
votes

In terminal:

defaults delete com.somecompany.someapp

10
votes

BTW, I've just released a GUI app that may be more convenient than working with the defaults command:

http://www.tempel.org/PrefsEditor

It works practically the same as Xcode's plist editor, but affects the user's app preferences directly.

To delete all your prefs, you could open your prefs in my Prefs Editor, Select All, then delete them with the Backspace or Delete key, and they're instantly all gone.

However, for this particular task, using defaults delete might still be quicker, especially if you put the command into a text file ending in ".command", and make it executable (with chmod +x). Then you can double click it from the Finder to execute it.