Set preferences, the macOS user defaults system works with both the OS and with individual applications.

      defaults [host] Actions Options

      defaults help

   read [domain [key]]      Print defaults to standard output

   read-type domain key     Print the plist type

   write domain key 'value' Save a default value

   write domain 'plist'     Save plist (a property list) as a default:

   rename domain old_key new_key  Rename a domain key.

   delete [domain [key]]    Remove key.
                            (for most applications this will return the behaviour
                             to the original default values) 
   domains                  Print all the domains in the user's defaults system.

   defaults [host] find word 
                            Search for word in the user's defaults, and
                            print a list of matches.

   Host  Optionally you can restrict changes to a specific host
         by default changes will apply to any host.
         [-host hostname]  Restrict to a remote machine.
         [-currentHost]    Restrict to the host the user is currently logged into.

Options: See below

If you change a default that belongs to a running application, the application won't see the change and might even overwrite the default.

In general you should close an application before changing its defaults, in the case of Dock and Finder defaults - restart them after applying the default with the killall command :
Restart the Dock: killall Dock
Restart the Finder: killall Finder

Data Types

defaults write ... -bool true
is not the same as defaults write ... true
The first will write a boolean value, while the second will write a string,
you can check the Data Type of an existing default with defaults read-type

Preferences are stored in a set of files under ~/Library/Preferences, however using the defaults command is much safer than manually editing a .plist file. The cfprefsd daemon manages and caches updates to preference files. If you modify the file directly, the changes will not propagate through the cache managed by the daemon.

The defaults command can read any plist file with a path minus the .plist extension


Disable the macOS Crash reporter (Crash dialog that normally appears after an application halts.)
$ defaults write DialogType none

To re-enable the crash reporter (default)
$ defaults write DialogType prompt

Read values from .plist file by specifying the path minus the .plist extension:
$ defaults read /Applications/ CFBundleIdentifier

$ defaults read /Applications/ CFBundleVersion

A long list of preferences that can be set in macOS and macOS applications can be found over in the How-to section.

     Specifying domains:

     domain    A full domain name of the form com.companyname.appname. 

                     defaults read

     -app application
               The name of an application:

                     defaults read -app TextEdit

     filepath  Domains can also be specified as a path to an arbitrary plist
               file, omitting the '.plist' extension. For example:

                     defaults read ~/Library/Preferences/

               normally gives the same result as the two previous examples.

               In the following example:

                     defaults write ~/Desktop/TestFile foo bar

               will write the key 'foo' with the value 'bar' into the plist
               file 'TestFile.plist' that is on the user's desktop. If the
               file does not exist, it will be created. If it does exist, the
               key-value pair will be added, overwriting the value of 'foo' if
               it already existed.

               WARNING: The defaults command will be changed in an upcoming
               major release to only operate on preferences domains. General
               plist manipulation utilities will be folded into a different
               command-line program.

     -g | -globalDomain | NSGlobalDomain
               Specify the global domain.
               '-g' and '-globalDomain' can be used as synonyms for NSGlobalDomain.

     Specifying value types for preference keys:

                 If no type flag is provided, defaults will assume the value
                 is a string. For best results, use one of the type flags,
                 listed below.

     -string     Specify a string as the value for the given preference key.

     -data       Specify a bunch of raw data bytes as the value for the given preference key.
                 The data must be provided in hexadecimal.

     -int[eger]  Specify an integer as the value for the given preference key.

     -float      Specify a floating point number as the value for the given preference key.

     -bool[ean]  A boolean as the value for the given preference key.
                 The Value must be TRUE, FALSE, YES, or NO (not case sensitive).
                 True/Yes evaluate to 1, False/No evaluate to 0.

     -date       Specify a date as the value for the given preference key.

     -array      Specify an array as the value for the given preference key:

                       defaults write somedomain preferenceKey -array element1 element2 element3

                 The specified array overwrites the value of the key if the  key was present at
                 the time of the write. If the key was not  present, it is created with the new

     -array-add  Add new elements to the end of an array for a key which has an array as its value.
                 Usage is the same as -array above. If the key was not present, it is created
                 with the specified array as its value.

     -dict       Add a dictionary to the defaults database for a domain.
                 Keys and values are specified in order:

                       defaults write somedomain preferenceKey -dict key1 value1 key2 value2

                 The specified dictionary overwrites the value of the key if  the key was present
                 at the time of the write. If the key was not present, it is created with the new value.

     -dict-add   Add new key/value pairs to a dictionary for a key which has a dictionary as its value.
                 Usage is the same as -dict above. If the key was not present, it is created with the
                 specified dictionary as its value.

Defaults allows users to read, write, and delete macOS user defaults from a command-line shell. macOS applications and other programs use the defaults system to record user preferences and other information that must be maintained when the applications aren't running (such as default font for new documents, or the position of an Info panel). Some settings can be changed through an application’s Preferences, but many are not shown in the GUI but can still be changed using defaults.

In most cases the current value can be read with defaults read… it is worth checking the current setting before writing a new default (with defaults write…) just in case you want to revert to the old settings. If defaults read… returns 'does not exist' that means there is no setting currently stored, you can remove a setting with defaults delete…

User defaults belong to domains, which typically correspond to individual applications. Each domain has a dictionary of keys and values representing its defaults; for example, "Default Font" = "Helvetica". Keys are always strings, but values can be complex data structures comprising arrays, dictionaries, strings, and binary data. These data structures are stored as XML Property Lists.

Though all applications, system services, and other programs have their own domains, they also share a domain named NSGlobalDomain. If a default isn't specified in the application's domain, but is specified in NSGlobalDomain, then the application uses the value in that domain.

A property list (or plist) can contain multiple values:

e.g. to write a single value:
  defaults write com.ss64.myapp "Default Color" '(255, 0, 0)'

To write two values (plist)
  defaults write com.ss64.myapp '{ "Default Color" = (255, 0, 0);
                                   "Default Font" = Helvetica; }';

Defaults can be structured in very complex ways, making it difficult for the user to decipher or modify them.

“I am a leader by default, only because nature does not allow a vacuum” ~ Desmond Tutu

Related macOS commands:

PlistBuddy - read and write values to plists
Awesome macOS Command Line - A large collection of macOS defaults.
Show hidden files.scpt - Toggle the display of hidden files in Finder (will restart finder).

Copyright © 1999-2022
Some rights reserved