defaults — the Apple settings database

The defaults check searches the local macOS defaults database, and asserts that keys are present or missing. This database contains the configuration of applications that use it, including the standard system preferences and well-behaved third-party apps.


Check that a value is set:

domain = 'Apple Global Domain'
key    = 'AppleAquaColorVariant'
value  = 6

Because this uses the defaults command, you can pass a valid value as the wrong type (such as the string '6' instead of the number 6) and still have it be set to the correct type.

Check that a value is not set:

domain = 'Apple Global Domain'
key    = 'TireCount'
state  = 'missing'

Some applications will store their preferences in a separate file. Safari, for example, puts its settings in a file deep within ~/Library/Containers. To check it, use file instead of domain:

file  = '~/Library/Containers/'
key   = 'ShowIconsInTabs'
value = '1'

List of parameters

domainstringThe defaults domain.
filestringPath to the defaults file on disk.
keystringThe defaults key.
statestringWhether the key should be present. This can be 'present' or 'missing'.
valuestring, array, or booleanThe value to expect.