如何在最新的mac OSX中替换App配置文件 | How-to: Replace preference files in Mavericks | also works on yosemite , el capitan

Something many people do, myself included, is copy an application’s preferences file—either from one Mac to another (as a quick way of getting an app configured to my liking) or to replace a damaged/lost preferences file using a Time Machine backup. Until recently, this process was really simple: quit the app in question, trash the existing prefs file, insert the new prefs file, launch app.

Enter OS X 10.9, aka Mavericks, aka “the easy prefs copy killer.” Apple has made changes to the way the preferences system works in Mavericks, and one casualty of those changes is the easy replacement of an application’s preferences file. A brief bit of before-and-after, and then we’ll get to the fix—or just click the Read More link to jump right to the fix.

In prior versions of OS X, preferences files were always read by the application at launch. So as long as the app wasn’t running, if you replaced its preference file, it would read the new file the next time you launched the program.

In Mavericks, preferences are managed by a background daemon, cfprefsd. This service reads the preferences file once, when you first run the app. It then (I believe) receives notifications if you change the program’s settings while the program is running, and then writes them to the actual preferences file at certain points in time. But cfprefsd always has a copy of those settings in its cache, and that’s what the app gets when it checks its settings. (This reduces hard disk access, which is important in conserving battery life in laptops.)

Here’s the important bit: After you’ve launched an app once, it seems that any subsequent launches also get their preferences from cfprefsd. So if you try the old “replace the prefs while the app isn’t running” trick, you’ll be quite surprised to find that your program launches with its previous settings. It will do this even if you simply delete (via Finder) the old prefs file!

So how do you get around this aggressive caching of preference files?

I’m aware of two solutions, though there may be others (please comment, if you know of a better way).

最好的解决方案:best answer:


Update based on comments: The best solution, per the comments below, is to quit the app, open Terminal, paste killall cfprefsd then press Return. This relaunches the prefs system; now relaunch the app, and it should read the modified prefs file.


Method One:

  1. Quit the app, and make sure it is not set to run at login.
  2. Delete the app’s prefs file (typically in ~/Library/Preferences, for non-sandboxed applications).
  3. Logout.
  4. Login.
  5. Copy the prefs file you want to use into its home.
  6. Launch the app.

Method Two:

  1. Quit the app, leaving the ‘bad’ prefs file in place.
  2. Open Terminal, paste the following, and press Return: defaults delete com.COMPANY_ID.APP_ID. Note that COMPANY_ID and APP_ID are taken from the name of the app’s preferences file. Using our own Moom for example, the preferences file is named com.manytricks.Moom.plist, so the command would be defaults delete com.manytricks.Moom.
  3. Copy the prefs file you want to use into the ~/Library/Preferences folder.
  4. Launch the app.

    I’ve tested both of these methods and found them to work, but would love to discover there’s an easier solution.

    Net net, if you want to replace prefs files in Mavericks, it’s now more complicated than it used to be…but it is still possible.

from:https://manytricks.com/blog/?p=3049

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注