salt.modules.macdefaults

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

salt.modules.macdefaults.cast_value_to_vtype(value, vtype)

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"
value

The value to be converted

vtype

The type to convert the value to. Valid types are string, int[eger], float, bool[ean], date, data, array, array-add, dict, dict-add

Raises:

ValueError -- When the value cannot be converted to the specified type

Returns:

The converted value

New in version 3008.0.

salt.modules.macdefaults.delete(domain, key, user=None, key_separator=None)

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='.'
domain

The name of the domain to delete from

key

The key of the given domain to delete. It can be a nested key separated by key_separator.

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.

user

The user to delete the defaults with

salt.modules.macdefaults.read(domain, key, user=None, key_separator=None)

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='.'
domain

The name of the domain to read from

key

The key of the given domain to read from. It can be a nested key/index separated by key_separator.

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.

user

The user to read the defaults from

Returns:

The current value for the given key, or None if the key does not exist.

salt.modules.macdefaults.write(domain, key, value, vtype=None, user=None, key_separator=None, dict_merge=False, array_add=False, type=None)

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"
domain

The name of the domain to write to

key

The key of the given domain to write to. It can be a nested key/index separated by key_separator.

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.

value

The value to write to the given key. Dates should be in the format 'YYYY-MM-DDTHH:MM:SSZ'

vtype

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.

type

Deprecated! Use vtype instead type collides with Python's built-in type() function This parameter will be removed in 3009

user

The user to write the defaults to

dict_merge

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.

array_add

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.

Raises:
  • KeyError -- When the key is not found in the domain

  • IndexError -- When the key is not a valid array index