45

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.

3
  • 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
    Feb 13, 2014 at 17:58
  • 2
    Well, yea, that will do it. But rebooting your computer between each build and run is NOT a practical solution.
    – Bryan
    Mar 18, 2014 at 20:51
  • 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
    Mar 18, 2014 at 21:20

4 Answers 4

61

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.

12
  • 7
    You can use 'defaults delete' to delete preferences in a cache-friendly way. Oct 10, 2013 at 23:36
  • 1
    defaults delete will only work when the preferences system is working normally :) if it doesn't work then, please file a bug, that's not expected Oct 25, 2013 at 6:28
  • 2
    Shon - are you with Apple? I can promise you, I didn't "muck around" with this process. I used Finder to delete my app's plist file, then wasted an hour of my life trying to figure out why OS X wasn't behaving. Deleting the plist in the Finder SHOULD clear the cached version. That it does not is an oversight on Apple's end. When the user deletes that file, it is ABSOLUTELY CLEAR what his intention is: nuke the prefs for app X.
    – Bryan
    Oct 28, 2013 at 21:49
  • 3
    The trouble is that there are roughly 4,549,312 webpages on the Internet that explain to users how to fix "misbehaving" apps. Step #1 is invariably: "Go to ~/Library/Preferences" and delete the app's preference file. This, apparently, no longer works on Mavericks; you must now tell users to go through the terminal and use 'defaults delete'. As far as I'm concerned, that's a bug. cfprefsd should be checking to see if the plist on disk is newer or deleted before it blindly uses its cached copy.
    – Bryan
    Oct 28, 2013 at 21:55
  • 1
    If you prefer using the CLI, I just tried "killall cfprefsd" and it seems to work too. Early days still. It's possible there is some new command to make plist replacement a bit easier. And if there isn't I imagine there are plenty of AppleCare employees who will ask Apple engineering to add one. Oct 29, 2013 at 13:53
15

In terminal:

defaults delete com.somecompany.someapp

2
  • 1
    This works... most of the time. I've still had instances where I couldn't get the app to start clean after using this terminal command.
    – Bryan
    May 28, 2014 at 1:25
  • Works great!! Event for reading and writing values! Better than any plist editor ..
    – col.panic
    May 13, 2015 at 12:11
14

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

killall -u $USER cfprefsd

3
  • 1
    Even though it might appear to work, I don't think that's safe as it might damage recently set prefs of other apps as well. Hence downvoted. Dec 21, 2013 at 13:32
  • Oh, sorry, I only now realize that you wrote that the kill does flush its cache. That'd mean that the process is not killed hard but is asked (signalled) to quit, allowing it to perform the flush operation before quitting. In that case, my downvote was unjustified. I cannot revoke it unless you update your answer. Feb 7, 2014 at 21:07
  • 1
    Thomas' concern is valid, however 'defaults delete' didn't work for me and this did (my use case was replacing the plist manually from a backup). I think the risk is manageable if you know what you are doing.
    – Jochem
    Nov 22, 2015 at 10:09
10

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.

1
  • That's a wonderful little tool and a great help when debugging things. Thank you for sharing it! Sep 5, 2014 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.