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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/410013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:00:02  来源:igfitidea点击:

Where do OSX applications typically store user configuration data?

macosinstaller

提问by Rngbus

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.

我注意到在 OSX 上,安装通常是一个拖放一个文件的方式。我假设该文件是所有应用程序必需位的存档,并且应用程序直接从中运行。应用程序在哪里存储配置数据,特别是当有多个用户时每个用户的设置?在 Windows 上,此类内容可能会出现在 HKLU 或 HKLM 下的注册表中,或者位于用户或所有用户的 Application Data 文件夹中。

回答by harms

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

在 /Users/username/Library/Preferences 中。您还会看到一些内容被放置在 /Users/username/Library/Application Support 中。

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.

这两个文件夹在 /Users 之外都有相应的全局位置,即 /Library 下。然而,出于显而易见的原因,这些应用程序似乎很少使用这些。

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.

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

Edit: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

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

回答by ThorstenC

Also /Users/username/Library/Containersand /Users/username/Library/Group Containersare places to look for.

/Users/username/Library/Containers/Users/username/Library/Group Containers一些地方寻找。

回答by Mike Heinz

As an addendum to harms' answer, I would note that, like the windows registry, OS X preferences are deliberately not deleted when the app is removed but, unlike the windows registry, preferences can migrate from machine to machine as you upgrade your Mac and use the "user migration" facility.

作为伤害答案的补充,我会注意到,与 Windows 注册表一样,删除应用程序时不会删除 OS X 首选项,但与 Windows 注册表不同,当您升级 Mac 和使用“用户迁移”工具。

This can lead to surprising results such as installing "NeatoApp 2008" and discovering that it knows all the settings you chose for "NeatoApp 2003" even though the 2003 version was never installed on your current machine.

这可能会导致令人惊讶的结果,例如安装“NeatoApp 2008”并发现它知道您为“NeatoApp 2003”选择的所有设置,即使您当前的计算机上从未安装过 2003 版本。