Sub topic 13
Inspecting and changing trackpad preferences from Terminal
This chapter assumes you know how to open Terminal, can run a command, and have already set gestures in System Settings. You will use the defaults command to read and write the same preferences that System Settings stores.
What `defaults` does
macOS keeps app and system preferences in property list (plist) files. A plist is a structured file that stores keys and values. The defaults command reads and writes these files without you opening them directly.
Each preference lives in a domain, which is usually an app or system component. A domain holds keys, and each key has a value. Trackpad settings use two domains:
| Domain | What it holds |
|---|---|
| `com.apple.AppleMultitouchTrackpad` | Settings for the built-in trackpad, such as tap to click |
| `NSGlobalDomain` | Settings shared by all apps, such as natural scrolling |
Bluetooth trackpads use a different domain, com.apple.driver.AppleBluetoothMultitouch.trackpad. If a command for the built-in trackpad has no effect on your external device, try that domain.
Reading a preference
The read subcommand prints a value. This command checks tap to click:
defaults read com.apple.AppleMultitouchTrackpad ClickingIt prints 1 when tap to click is on. If the key has never been set, defaults reports that the pair does not exist. That message does not mean something is broken. It means the preference still has its default value.
Natural scrolling is stored in the global domain:
defaults read NSGlobalDomain com.apple.swipescrolldirectionA result of 1 means natural scrolling is on. A result of 0 means it is off.
Writing a preference
The write subcommand changes a value. You must give the value's type. Tap to click needs a Boolean, so use -bool, and the tap behavior key needs an integer, so use -int:
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1The second command uses -currentHost. This option writes to the settings for this specific Mac instead of the settings shared by every Mac on your account. Tap to click needs both writes.
The change may not apply until you log out and log back in. Running processes keep their cached preferences until they reload them.
A safe workflow
Follow these steps whenever you change a preference:
- Read the current value and write it down.
- Write the new value with the correct type.
- Read the value again to confirm it was stored.
- Log out and log in, then test the gesture.
- If it misbehaves, write the old value back, or use
defaults deleteto remove your key and return to the default.
defaults delete com.apple.AppleMultitouchTrackpad ClickingCommon errors
- "The domain/default pair does not exist." The key has never been set. Treat it as the default value.
- No visible effect after a write. The setting needs a logout, or you wrote to the wrong domain for your device.
- Wrong type. Writing
-string trueinstead of-bool truestores text, and the system may ignore it. - Setting reverts. System Settings rewrote the value when you opened its pane.
Exercise
You run defaults read com.apple.AppleMultitouchTrackpad Clicking and Terminal says the pair does not exist. What does this tell you, and what is a safe way to turn on tap to click from Terminal?
Show answer
The key has never been written, so tap to click is using its default value (off). To turn it on, run defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true and defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1, read the value back to confirm it, then log out and in. System Settings is still the supported method.
Exercise
Which command shows whether natural scrolling is on, and what does a result of 0 mean?
Show answer
defaults read NSGlobalDomain com.apple.swipescrolldirection. A result of 0 means natural scrolling is off.