Monday, February 24, 2014

Key directories for Mac apps

Table 1-1  Key directories for Mac apps
DirectoryDescription
Applications directoryThis is the installation directory for your app bundle. The path for the global Applications directory is /Applications but each user directory may have a local applications directory containing user-specific apps. Regardless, you should not need to use this path directly. To access resources inside your application bundle, use an NSBundle object instead.
For more information about the structure of your application bundle and how you locate resources, see “The OS X Application Bundle.”
Home directoryThe configuration of your app determines the location of the home directory seen by your app:
  • For apps running in a sandbox in OS X v10.7 and later, the home directory is the app’s container directory. For more information about the container directory, see “The Keychain.”
  • For apps running outside of a sandbox (including those running in versions of OS X before 10.7), the home directory is the user-specific subdirectory of /Users that contains the user’s files.
To retrieve the path to the home directory, use the NSHomeDirectory function.
Library directoryThe Library directory is the top-level directory for storing private app-related data and preferences. There are several Library directories scattered throughout the system but you should always use the one located inside the current home directory.
Do not store files directly at the top-level of the Library directory. Instead, store them in one of the specific subdirectories described in this table.
In OS X v10.7 and later, the Finder hides the Library directory in the user’s home folder by default. Therefore, you should never store files in this directory that you want the user to access.
To get the path to this directory use the NSLibraryDirectory search path key with the NSUserDomainMask domain.
Application Support directory The Application Support directory is where your app stores any type of file that supports the app but is not required for the app to run, such as document templates or configuration files. The files should be app-specific but should never store user data. This directory is located inside the Library directory.
Never store files at the top level of this directory: Always put them in a subdirectory named for your app or company.
If the resources apply to all users on the system, such as document templates, place them in /Library/Application Support. To get the path to this directory use the NSApplicationSupportDirectory search path key with the NSLocalDomainMask domain. If the resources are user-specific, such as workspace configuration files, place them in the current user’s ~/Library/Application Support directory. To get the path to this directory use the NSApplicationSupportDirectory search path key with the NSUserDomainMask domain.
Caches directoryThe Caches directory is where you store cache files and other temporary data that your app can re-create as needed. This directory is located inside the Library directory.
Never store files at the top level of this directory: Always put them in a subdirectory named for your app or company. Your app is responsible for cleaning out cache data files when they are no longer needed. The system does not delete files from this directory.
To get the path to this directory use the NSCachesDirectory search path key with the NSUserDomainMask domain.
Movies directoryThe Movies directory contains the user’s video files.
To get the path to this directory use the NSMoviesDirectory search path key with the NSUserDomainMask domain.
Music directoryThe Music directory contains the user’s music and audio files.
To get the path to this directory use the NSMusicDirectory search path key with the NSUserDomainMask domain.
Pictures directoryThe Pictures directory contains the user’s images and photos.
To get the path to this directory use the NSPicturesDirectory search path key with the NSUserDomainMask domain.
Temporary directoryThe Temporary directory is where you store files that do not need to persist between launches of your app. You normally use this directory for scratch files or other types of short-lived data files that are not related to your app’s persistent data. This directory is typically hidden from the user.
Your app should remove files from this directory as soon as it is done with them. The system may also purge lingering files from this directory at system startup.
To get the path to this directory use the NSTemporaryDirectory function.

No comments:

Post a Comment