Set defaults settings on macOS.
This module uses defaults cli under the hood to import and export defaults on macOS.
However, it uses the plistlib package to handle the conversion between the defaults output and Python dictionaries. It is also used to create the plist files to import the defaults.
Read plistlib documentation for more information on how the conversion is done: https://docs.python.org/3/library/plistlib.html
Convert the value to the specified vtype. If the value cannot be converted, a ValueError is raised.
CLI Example:
salt '*' macdefaults.cast_value_to_vtype "1.35" "float"
salt '*' macdefaults.cast_value_to_vtype "2024-06-23T09:33:44Z" "date"
salt '*' macdefaults.cast_value_to_vtype "737720347.089987" "date"
The value to be converted
The type to convert the value to. Valid types are string, int[eger], float, bool[ean], date, data, array, array-add, dict, dict-add
ValueError -- When the value cannot be converted to the specified type
The converted value
New in version 3008.0.
Delete a default from the system
CLI Example:
salt '*' macdefaults.delete com.apple.CrashReporter DialogType
salt '*' macdefaults.delete NSGlobalDomain ApplePersistence
salt '*' macdefaults.delete NSGlobalDomain key.with.dots key_separator='.'
The name of the domain to delete from
The key of the given domain to delete. It can be a nested key separated by key_separator.
The separator to use when splitting the key into a list of keys. If None, the key will not be split (Default).
New in version 3008.0.
The user to delete the defaults with
Read a default from the system
CLI Example:
salt '*' macdefaults.read NSGlobalDomain ApplePersistence
salt '*' macdefaults.read NSGlobalDomain key.with.dots-subKey key_separator="-"
salt '*' macdefaults.read com.apple.Dock persistent-apps.1.title-data.file-label key_separator='.'
The name of the domain to read from
The key of the given domain to read from. It can be a nested key/index separated by key_separator.
The separator to use when splitting the key into a list of keys. If None, the key will not be split (Default).
New in version 3008.0.
The user to read the defaults from
The current value for the given key, or None if the key does not exist.
Write a default to the system
CLI Example:
salt '*' macdefaults.write com.apple.Finder DownloadsFolderListViewSettingsVersion 1
salt '*' macdefaults.write com.apple.Finder ComputerViewSettings.CustomViewStyle "icnv" key_separator='.'
salt '*' macdefaults.write com.apple.Dock lastShowIndicatorTime 737720347.089987 vtype=date
salt '*' macdefaults.write NSGlobalDomain com.apple.sound.beep.sound "/System/Library/Sounds/Blow.aiff"
The name of the domain to write to
The key of the given domain to write to. It can be a nested key/index separated by key_separator.
The separator to use when splitting the key into a list of keys. If None, the key will not be split (Default).
New in version 3008.0.
The value to write to the given key. Dates should be in the format 'YYYY-MM-DDTHH:MM:SSZ'
The type of value to be written.
Valid types are string, int[eger], float, bool[ean], date and data.
dict and array are also valid types but are only used for validation.
dict-add and array-add are supported too. They will behave as their counterparts dict and array but will set their corresponding sibling options dict_merge and array_add to True.
This parameter is optional. It will be used to cast the values to the specified type before writing them to the system. If not provided, the type will be inferred from the value.
Useful when writing values such as dates or binary data.
Deprecated! Use vtype instead type collides with Python's built-in type() function This parameter will be removed in 3009
The user to write the defaults to
Merge the value into the existing dictionary. If current value is not a dictionary this option will be ignored. This option will be set to True if vtype is dict-add.
New in version 3008.0.
Append the value to the array. If current value is not a list this option will be ignored. This option will be set to True if vtype is array-add.
New in version 3008.0.
KeyError -- When the key is not found in the domain
IndexError -- When the key is not a valid array index