OSX应用程序通常在哪里存储用户配置数据?

问题描述:

我在OSX上注意到,安装通常只是拖放一个文件.我假设该文件是所有应用程序必不可少的文件的存档,并且该应用程序直接从该文件运行.应用程序在哪里存储配置数据,特别是在有多个用户的情况下按用户设置存储的配置数据?在Windows上,这种类型的内容可能会在用户或所有用户的HKLU或HKLM下的注册表中,或在Application Data文件夹中.

I've noticed on OSX, installation is frequently a drag and drop one file kinda deal. I assume that file is an archive of all the applications necessary bits and that the application runs directly from it. Where does the application store configuration data, particularly per user settings when there are multiple users? On Windows, this type of stuff might go in the registry under HKLU or HKLM, or in the Application Data folder for the user or for all users.

在/Users/username/Library/Preferences中.您还会在/Users/username/Library/Application Support中看到一些内容.

In /Users/username/Library/Preferences. You also see some stuff being placed in /Users/username/Library/Application Support.

这两个文件夹都在/Users外部(即/Library下)具有相应的全局位置.但是,由于显而易见的原因,这些应用似乎很少被使用.

Both of these folders have corresponding global locations outside /Users, namely under /Library. These however seem to be used very little by applications as such, for obvious reasons.

OSX本地应用程序的首选项格式通常是.plist(属性列表)文件,其名称使用反向域名语法给出.有一个名为属性列表编辑器"的独立应用程序,它允许您查看和编辑此类文件. (我认为这是XCode/developer-tools下载的一部分.)当然,没有什么可以阻止您使用自己的首选项存储系统,自然地,大多数跨平台的应用程序倾向于这样做,但是首选项仍然应该放在/Users/username/Library/Preferences目录中.

The format of the preferences for OSX-native applications are usually .plist (property-list) files with a name given in reverse-domain name syntax. There is a standalone application called Property List Editor which allows you to view and edit such files. (I think it's part of the XCode/developer-tools download.) Of course there's nothing to prevent you from using your own preference storage system, and naturally applications that are mostly cross-platform will tend to do this, but the preferences should nevertheless be placed in the /Users/username/Library/Preferences directory.

编辑:如果您正在为Mac编写软件,并且正在使用Cocoa框架,那么Apple拥有此Cocoa API部分的文档,该文档涉及存储和检索首选项设置. :用户默认设置编程

If you're writing software for the Mac and you're using the Cocoa framework, then Apple has this document for the part of the Cocoa API that deals with storing and retrieving preference settings: User Defaults Programming