defaults · macOS command

Also known as: defaults write

On this page 7

defaults is the macOS command for reading, writing and deleting user and system preferences stored in property list domains, making it one of the core tools of Terminal & scripting on the Mac. Each application and many system components keep their settings as key-value pairs inside a preference domain, and defaults gives direct command-line access to those values, including many that have no switch in the graphical interface.

The phrase defaults write is often used as a synonym, because writing a value is the most common reason people run the tool. Administrators use it to configure Macs consistently by script, and power users use it to enable hidden behaviors in the Finder, the Dock and other built-in apps.

How the preferences system works

macOS stores preferences in property list files, typically under ~/Library/Preferences for the current user and /Library/Preferences for all users. Applications do not read these files directly; they ask the cfprefsd daemon, which caches values in memory and writes them back to disk at its own pace.

This caching is the reason why editing a plist file by hand is unreliable: cfprefsd may overwrite the change with its cached copy. The defaults command talks to cfprefsd through the same Core Foundation preferences API that applications use, so its changes are seen consistently.

The table below lists the main preference scopes that the command can address.

ScopeExample domain or flagTypical file location
Application domaincom.apple.finder~/Library/Preferences/com.apple.finder.plist
Global domainNSGlobalDomain or -g~/Library/Preferences/.GlobalPreferences.plist
Current host only-currentHost flag~/Library/Preferences/ByHost/
System-wide domain/Library/Preferences/... with sudo/Library/Preferences/
Sandboxed app domainBundle identifier~/Library/Containers/<id>/Data/Library/Preferences/
Preference domains and scopes

Core subcommands and value types

The command follows the pattern defaults [scope] verb domain key [type value]. A small set of verbs covers nearly every administrative task, and explicit type flags prevent a value from being stored with the wrong data type.

VerbPurposeExample
readShow one key or a whole domaindefaults read com.apple.dock autohide
writeCreate or change a valuedefaults write com.apple.dock autohide -bool true
deleteRemove a key or a domaindefaults delete com.apple.dock autohide
read-typeReport the stored data typedefaults read-type com.apple.dock tilesize
domainsList all known domainsdefaults domains
findSearch keys and values by worddefaults find autohide
export / importSave or load a whole domaindefaults export com.apple.dock dock.plist
Main verbs of the defaults command

Values are typed. Writing true without -bool stores the string “true”, which many applications ignore, so always specifying the type is the decisive habit for reliable results.

FlagStored typeTypical use
-boolBooleanFeature switches
-intIntegerSizes, counts, delays in steps
-floatFloating-point numberAnimation durations, scales
-stringStringPaths, identifiers, modes
-array and -array-addOrdered listLists of items or paths
-dict and -dict-addDictionaryNested key-value settings
Value type flags

Making a change take effect

Writing a value does not guarantee that a running application notices it. Most apps read preferences at launch, so the change appears only after the app is quit and reopened, or, for system components, after restarting the process with killall, for example killall Dock or killall Finder.

Some settings are read only at login, so a logout or restart is required. Changing preferences of a running app can also be undone when that app writes its in-memory state back on quit, which is why quitting the target app first is the safest order.

Sandboxed applications add another subtlety. Their preferences live inside the app container, and on recent macOS versions access to another app’s container may trigger a privacy prompt or require Full Disk Access for Terminal. Addressing the domain by its bundle identifier rather than by a file path lets cfprefsd locate the correct container automatically and avoids writing to a stale copy outside it. Reading a domain with defaults read before and after a change in System Settings is also the most practical way to discover which key controls a setting, because Apple documents only a fraction of them.

The command is one of several ways to configure a Mac, and choosing correctly depends on scale, persistence and enforcement. It changes values once; it does not stop a user from changing them back.

MethodScopeEnforcedBest suited for
defaults commandOne user or one MacNoQuick tweaks and setup scripts
PlistBuddyOne plist fileNoEditing nested structures in files
System SettingsOne userNoEveryday changes by end users
Configuration profileManaged MacsYesFleet policies through MDM
AppleScript or osascriptRunning appsNoSettings exposed through scripting
Configuration methods compared

In organizations, configuration profiles delivered by MDM take priority over values written with this tool: a managed key shows the enforced value, and local writes have no effect on it. The command remains useful for testing a key before building a profile.

Risks and good practice

The tool performs no validation of keys or values, so a typo silently creates an unused key and a wrong type can make an application misbehave. Undocumented keys may also change or disappear between macOS releases, which makes long-lived tweaks fragile.

  • Back up first: run defaults export on the domain before a significant change.
  • Specify the type: always add -bool, -int or another type flag.
  • Quit the app: close the target application before writing to its domain.
  • Use delete to revert: deleting a key restores the application default.
  • Avoid sudo for user settings: writing with sudo targets root preferences, not the user.

A non-technical view

Every app on a Mac keeps a small list of settings, such as which folder opens first or how big the Dock icons are. Most of these settings have buttons in the app. Some do not.

The defaults command is a way to open that list and change entries by typing. It is like adjusting a thermostat with the service panel instead of the front dial. You get access to more options, but a wrong entry is not caught for you. Saving a copy first is the sensible step.

A concrete example

An IT technician at a design studio prepares 25 new Macs for staff. Every designer wants the same setup: file extensions always visible, the full path shown in the Finder title bar, and screenshots saved to a dedicated folder instead of the desktop.

The technician writes a short zsh script with three commands: defaults write NSGlobalDomain AppleShowAllExtensions -bool true, defaults write com.apple.finder _FXShowPosixPathInTitle -bool true and defaults write com.apple.screencapture location -string ~/Pictures/Screenshots, followed by killall Finder and killall SystemUIServer. Each Mac takes under a minute instead of about ten minutes of clicking through settings, and every machine ends up configured identically. Because staff may still adjust these preferences, the studio later moves the screenshot policy into an MDM profile.