Table of Contents

Defaults

Change macOS user preferences via command line
Way to Copy Mac OS X preferences into a shell file
defaults 命令详解

1. Command line

1.1 Basic command

defaults write com.apple.finder AppleShowAllFiles -string YES

Let’s take it apart to get familiar with the terminology used throughout this article:

1.2 Method

1.3 Domains — system components and installed apps

Domains are objects that contain settings for a particular system component, installed application or a configuration .plist file located in /Library/Preferences/.

# List all domains
defaults domains
defaults domains | tr ',' '\n'

2. Read/Write/Modify a key

2.1 A basic workflow to amend user defaults

  1. Print the settings for the notes app to find the right key.
  2. Check the value type for a given key.
  3. Write new settings.

2.2 The way to find the domain & key responsible for a setting

  1. Save a state before a change.
  2. Make a change through GUI.
  3. Save a state after a change.
  4. Find the difference.

2.3 Example: Systempreferences - Shortcuts

# Read global shortcuts
defaults read -g NSUserKeyEquivalents
defaults read-type -g NSUserKeyEquivalents
## Type is dictionary

# Write global shortcuts
defaults write -g "NSUserKeyEquivalents" -dict \
"Copy" "^C" \
"Paste" "^V" \
"Select All" "^A" \
"Cut" "^X" \
"Undo" "^Z" \
"Redo" "^Y" \
"Find..." "^F" \
"Replace" "^R" \
"Find Next" "\\Uf706" \
"Find Previous" "$\\Uf706" \
"Save..." "^S" \