Understanding and Using the 'defaults' Command on macOS (with examples)
- Osx
- December 17, 2024
The defaults
command is an incredibly powerful tool on macOS that allows users to read and write user preference settings for various applications. Designed as part of the Core Foundation framework, this command can manage configuration data, streamline user interface behavior, and alter system behavior without ever opening an application’s graphical interface. This command is especially useful for troubleshooting, customization, and optimizing application performance.
Use case 1: Reading system defaults for an application option
Code:
defaults read "application" "option"
Motivation:
You might find yourself needing to understand how an application behaves by default, such as what the standard settings are when you launch a program you haven’t personalized. Accessing these defaults allows users to verify application parameters without diving into complex configuration files or exploring the application interface manually.
Explanation:
defaults read
: Initiates a read command within the defaults tool, instructing the computer to fetch the stored value."application"
: Represents the application whose preferences you’re interested in. The application is usually represented by its bundle identifier, such ascom.apple.finder
for Finder."option"
: Is the specific setting or preference you wish to query about the application.
Example Output:
{
"option" = "default_value";
}
This output illustrates the default setting configured for the specified option of the chosen application.
Use case 2: Reading default values for an application option
Code:
defaults read -app "application" "option"
Motivation:
In some cases, it’s more intuitive to refer to an application by its name rather than its bundle identifier. This option allows you to easily read an option’s default value utilizing the application’s name, making it accessible for users who are not familiar with bundle identifiers.
Explanation:
-app
: A flag that allows users to use the application’s name instead of its bundle identifier."application"
: The literal name of the application (e.g., Safari, Finder)."option"
: Specifies which option of the application you wish to query.
Example Output:
{
"option" = "default_value";
}
The typical output provides insight into one default value associated with an application option when referring to the application by its name.
Use case 3: Searching for a keyword in domain names, keys, and values
Code:
defaults find "keyword"
Motivation:
When you want to find out if a particular keyword appears within your system’s defaults settings—perhaps tracing misconfigurations or simply learning more about the settings across applications—this command becomes invaluable. It saves time exploring manually and presents all results in a coherent manner.
Explanation:
find
: Is a command used to search through the defaults database."keyword"
: The term or string you’re looking to find within domain, key, or value names in your defaults.
Example Output:
Found 5 keys in domain 'com.apple.TextInput':
{
"exampleKey" = "keyword";
...
}
The example output locates instances of the keyword within key-value pairs across multiple domains, listing them effectively for further examination.
Use case 4: Writing the default value of an application option
Code:
defaults write "application" "option" -type value
Motivation:
Sometimes changing the functionality or visuals of an application requires adjusting its default settings. Whether it’s enabling a hidden feature, speeding up tasks, or customizing the interface, this command allows you to control these preferences straightforwardly.
Explanation:
write
: Indicates you are setting or changing a default value."application"
: Identifies the application you want to modify."option"
: Specifies which particular setting you are changing.-type
: Represents data type of the value being written (e.g., -string, -int).value
: The new value you are assigning to the option.
Example Output:
The command itself doesn’t produce output directly but modifies the system state to alter application behavior.
Use case 5: Speeding up Mission Control animations
Code:
defaults write com.apple.Dock expose-animation-duration -float 0.1
Motivation:
Improving productivity might involve refining the speed of macOS animations. For users who often navigate between multiple applications, reducing the animation duration in Mission Control can provide smoother and faster transitions. This specific command is optimized for enhancing user interface speed, leading to a more efficient workflow.
Explanation:
com.apple.Dock
: The bundle identifier for the Dock-related settings.expose-animation-duration
: The specific setting that influences the speed of animation for Mission Control.-float
: Indicates the data type of the value (floating-point number).0.1
: The new, faster duration value for animations.
Example Output:
This command typically doesn’t return output but the change can be observed in the increased speed of animations.
Use case 6: Deleting all defaults of an application
Code:
defaults delete "application"
Motivation:
When experiencing persistent application issues or simply starting over with configuration settings is needed, deleting all the default settings of an application can be a solution. It effectively restores applications to their out-of-box states without requiring a full reinstallation.
Explanation:
delete
: Command to remove all defaults."application"
: Specifies the application whose settings are being removed entirely.
Example Output:
Again, the command doesn’t produce direct output but rather returns the application to its original default setting, requiring recalibration or setup upon next use.
Conclusion:
The defaults
command is a versatile and essential tool for macOS users interested in managing and customizing their software environments. By offering advanced control over application and system defaults, this command simplifies many configuration tasks while empowering users to enhance their computer experience efficiently.