Equivalents of XDG_CONFIG_HOME and XDG_DATA_HOME on Mac OS X?

て烟熏妆下的殇ゞ 提交于 2019-12-02 16:40:38

I would use ~/Library/Application Support/script_name/. The subdirectories inside Application Support are used conventionally by various apps, including Apple's own softwares. But it's not enforced by the OS and not tied to apps inside /Applications. So you're perfectly free to create your own directory in it.

For the directory structure of OS X in general, see this Apple document.

jla

Comparing Apple's documentation for the various paths to the XDG Base Directory specifications approximates to the following locations:

  • XDG_CONFIG_HOME ▶︎ ~/Library/Preferences/
  • XDG_DATA_HOME ▶︎ ~/Library/
  • XDG_CACHE_HOME ▶︎ ~/Library/Caches/

Mapping XDG Base Directory Specification locations for "My App" on Mac OS X could look like this:

  • XDG_CONFIG_HOME ▶︎ ~/Library/Preferences/name.often.with.domain.myapp.plist
  • XDG_DATA_HOME ▶︎ ~/Library/My App/
  • XDG_CACHE_HOME ▶︎ ~/Library/Caches/My App/

These mappings seem pretty reasonable but they aren't exact. Some kinds of cache or data may be appropriate for ~/Library/Application Support/My App, and other may be best in the temp locations or the App bundle. All of it is by convention and the same reasons for using the best XDG_ locations apply to using the best locations on the Mac OS X system.

Your annoyance at ~/.myscript is in line with Apple's guidelines: "Don't pollute user space".

References:

I agree with OJFord's comment: if you are writing a script, simply follow the XDG Base Directory would be better.

Rationales:

  1. Names in XDG_CONFIG_HOME are typically small-case bare-names like git; the ones in ~/Library/Preferences/ are typically scoped with reversed domain names like com.apple.foo-bar, or first-letter-capital space-delimited names like Foo Bar.
  2. GUI applications have been following macOS conventions when they are placed in /Applications. You don't place your script in /Applications; you place them in UNIX-specific directorys. Better to be consistent.
  3. ~/Library/Preferences/ is full of .plists. No cross-platform script that I know is using property lists.
  4. Users may want to sync cross-platform configuration and macOS-only one separately.

For example, Git places their config file in XDG_CONFIG_HOME/git/config, not in ~/Library/Preferences/Git/config. Makes sense to me.

note

I made the point only for configuration files ($XDG_CONFIG_HOME) and data files ($XDG_DATA_HOME); for cache files it gets subtle. According to How-To Geek, ~/Library/Caches directory is excluded from Time Machine by default. I don’t care about cache folder since I back up neither directories anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!