Using the `defaults` Command (with examples)
- Osx
- November 5, 2023
1: Reading system defaults for an application option
defaults read "application" "option"
Motivation: This command allows you to view the current system defaults for a specific option within an application. It can be helpful for troubleshooting or understanding the current configuration of an application.
Explanation: This command reads and displays the value of a specific option within an application’s default preferences. The “application” argument refers to the name of the application, while the “option” argument refers to the specific option you want to retrieve.
Example Output:
$ defaults read "com.apple.finder" "FXPreferredViewStyle"
"icnv"
In this example, the command reads the value of the “FXPreferredViewStyle” option for the Finder application. The output “icnv” indicates that the preferred view style is set to icon view.
2: Reading default values for an application option
defaults read -app "application" "option"
Motivation: This command allows you to view the default values for a specific option within an application. By comparing the default values with the current system defaults, you can identify any customizations made.
Explanation: This command reads and displays the default value of a specific option within an application’s preferences. The “-app” option followed by the “application” argument specify the name of the application. The “option” argument refers to the specific option you want to retrieve.
Example Output:
$ defaults read -app "com.apple.Safari" "WebKitDeveloperExtras"
{
IncludeDebugMenu = 0;
IncludeInternalDebugMenu = 0;
ShowDictionaries = 0;
}
In this example, the command reads and displays the default values for the “WebKitDeveloperExtras” option within the Safari application. The output shows a dictionary with the default values for various sub-options.
3: Searching for a keyword in domain names, keys, and values
defaults find "keyword"
Motivation: This command enables you to quickly search for a keyword within domain names, keys, and values in the macOS user configuration. It helps to locate specific preferences related to a keyword or troubleshoot issues.
Explanation: This command searches for the specified keyword within domain names, keys, and values of the macOS user configuration. The “keyword” argument should be replaced with the term you want to search for.
Example Output:
$ defaults find "animation"
{
"com.apple.Dock" = {
"expose-animation-duration" = {
domain = "com.apple.Dock";
type = float;
value = "0.1";
};
};
}
In this example, the command searches for the keyword “animation” in the macOS user configuration. The output shows the matching domain name, key, type, and value for the “expose-animation-duration” preference in the “com.apple.Dock” domain.
4: Writing the default value of an application option
defaults write "application" "option" -type value
Motivation: This command is used to modify or set the default value of a specific option within an application. It allows customization of application preferences to suit personal needs.
Explanation: This command writes the specified “value” to the “option” within the default preferences of the given “application”. The “application” argument should be replaced with the name of the application, and the “option” argument should be replaced with the specific option you want to modify.
Example Output: (No output is displayed if the command executes successfully)
5: Speeding up Mission Control animations
defaults write com.apple.Dock expose-animation-duration -float 0.1
Motivation: This command is useful for adjusting the speed of Mission Control animations on macOS. Decreasing the animation duration can enhance productivity, providing a faster visual transition between spaces.
Explanation: This command writes the value “0.1” as a float data type to the “expose-animation-duration” option within the default preferences of the “com.apple.Dock” domain. It specifically modifies the animation duration for Mission Control.
Example Output: (No output is displayed if the command executes successfully)
6: Deleting all defaults of an application
defaults delete "application"
Motivation: This command is used to remove all default preferences associated with an application. It can be helpful when troubleshooting issues caused by conflicting or corrupted preferences.
Explanation: This command deletes all default preferences for the specified “application”. The “application” argument should be replaced with the name of the application you want to remove preferences for.
Example Output: (No output is displayed if the command executes successfully)
Conclusion
The defaults
command in macOS provides a flexible approach to manage and customize application preferences. By understanding and utilizing its various options, you can effectively read, modify, and delete default values to optimize your macOS user experience.