Sub topic 13
Inspecting and changing trackpad preferences from Terminal
What this chapter covers
Every setting you change in System Settings is stored as a preference. The defaults command lets you read and write those preferences from Terminal. This chapter shows how to inspect gesture settings, change them, and undo the change. It also explains why a change sometimes seems to do nothing.
This chapter assumes you have these prerequisites:
- You can open Terminal and run a command.
- You know where the trackpad and mouse panes of System Settings are.
- You have used the gestures from earlier chapters, such as tap to click, natural scrolling and three-finger drag.
Treat defaults as a way to inspect and automate. System Settings is the supported way to change gestures. The commands below can set a value that the Settings window does not yet reflect.
How preferences are stored
A preference is a key and a value stored inside a domain. A domain is a named bucket of settings, usually named after an app or a system component, such as com.apple.AppleMultitouchTrackpad. The special domain NSGlobalDomain holds settings shared by all apps.
Preferences are stored in property list files (.plist) under ~/Library/Preferences. You should not edit these files by hand. A background service called cfprefsd caches them and serves them to apps. The defaults command talks to that service, so it is safe to use.
Some values are stored per user and some per machine. The -currentHost flag selects the per-machine copy. A few trackpad settings exist in both places, which causes confusion later in this chapter.
Reading a preference
The command defaults read DOMAIN KEY prints one value. This example reads the tap-to-click setting for the built-in trackpad.
defaults read com.apple.AppleMultitouchTrackpad ClickingIt prints 1 when tap to click is on and 0 when it is off. If the key has never been set, defaults prints an error saying the domain and default pair does not exist. That message is not a fault. It means the system is using its built-in default, and nothing is stored yet.
Natural scrolling lives in the global domain.
defaults read NSGlobalDomain com.apple.swipescrolldirectionThe value 1 means natural scrolling is on, and 0 means it is off.
Reading a whole domain
If you omit the key, defaults read prints every stored key in that domain. This is the quickest way to see what your trackpad settings look like.
defaults read com.apple.AppleMultitouchTrackpadExpect keys such as Clicking, TrackpadThreeFingerDrag, TrackpadRightClick and TrackpadThreeFingerHorizSwipeGesture. The exact list depends on your macOS version and which settings you have changed. Do not assume a key exists on every Mac.
Finding a value's type
Before writing a value, check its type. Writing the wrong type is a common error.
defaults read-type com.apple.AppleMultitouchTrackpad ClickingThis prints something like Type is boolean. The types you will meet are boolean, integer and float.
Which domain applies to your device
The built-in trackpad and an external Magic Trackpad store settings in different domains.
| Device | Domain |
|---|---|
| Built-in Multi-Touch trackpad | `com.apple.AppleMultitouchTrackpad` |
| Bluetooth Magic Trackpad | `com.apple.driver.AppleBluetoothMultitouch.trackpad` |
| Magic Mouse | `com.apple.driver.AppleBluetoothMultitouch.mouse` |
| Settings shared across devices | `NSGlobalDomain` |
If a change has no effect, you may have written to the wrong domain for the device you are using. Read the same key from both trackpad domains to see which one your Mac actually stores.
defaults read com.apple.AppleMultitouchTrackpad Clicking
defaults read com.apple.driver.AppleBluetoothMultitouch.trackpad ClickingNote that on some Macs, the built-in trackpad settings are mirrored into the Bluetooth domain. When you use a Magic Trackpad and the built-in one together, set both domains.
Writing a preference
The command defaults write DOMAIN KEY -TYPE VALUE stores a value. The type flag is required for anything that is not a string. These two commands are commonly used to turn on tap to click.
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1The first command writes the per-user trackpad setting. The second writes the per-machine tap behavior in the global domain. Both are needed because the system consults each of them. The -currentHost flag must come before write.
Common type flags
| Flag | Meaning | Example |
|---|---|---|
| `-bool` | True or false | `-bool true` |
| `-int` | Whole number | `-int 1` |
| `-float` | Decimal number | `-float 1.5` |
| `-string` | Text | `-string "value"` |
A frequent mistake is writing -int 1 to a key stored as a boolean. The write succeeds, but macOS may ignore the value or treat it unpredictably. Always run read-type first.
Useful trackpad keys
These keys are widely used, but Apple does not document them. They can change between macOS releases. Check each with read before depending on it.
| Setting | Domain | Key | Type |
|---|---|---|---|
| Tap to click | `com.apple.AppleMultitouchTrackpad` | `Clicking` | boolean |
| Three-finger drag | `com.apple.AppleMultitouchTrackpad` | `TrackpadThreeFingerDrag` | boolean |
| Natural scrolling | `NSGlobalDomain` | `com.apple.swipescrolldirection` | boolean |
| Tracking speed | `NSGlobalDomain` | `com.apple.trackpad.scaling` | float |
For example, to read your tracking speed, run this command.
defaults read NSGlobalDomain com.apple.trackpad.scalingLarger values mean a faster pointer. If no value prints, the system is using its default speed.
Making changes safely
Preferences have no undo button, so build your own. Follow this routine before you change anything.
- Export the domain to a backup file.
- Read the current value and note it.
- Write the new value.
- Log out and back in, then test the gesture.
- If anything is wrong, restore the backup or delete the key.
This script does steps 1 to 3 for tap to click.
#!/bin/bash
set -e
DOMAIN="com.apple.AppleMultitouchTrackpad"
BACKUP="$HOME/trackpad-prefs-backup.plist"
defaults export "$DOMAIN" "$BACKUP"
echo "Backed up to $BACKUP"
echo -n "Current Clicking value: "
defaults read "$DOMAIN" Clicking 2>/dev/null || echo "not set"
defaults write "$DOMAIN" Clicking -bool true
echo "New Clicking value: $(defaults read "$DOMAIN" Clicking)"To restore from the backup, use defaults import. This replaces the whole domain with the backup contents.
defaults import com.apple.AppleMultitouchTrackpad "$HOME/trackpad-prefs-backup.plist"To undo a single key and return it to the system default, delete it.
defaults delete com.apple.AppleMultitouchTrackpad ClickingWhen a written value does not take effect
Work through these causes in order.
- The change is cached. Log out and log back in. Restarting the Mac also works.
- Wrong domain. Your device may use the Bluetooth domain instead of the built-in one. Compare the reads shown earlier.
- Wrong type. Run
read-typeand rewrite the value with the matching flag. - Missing
-currentHost. Some keys, such ascom.apple.mouse.tapBehavior, have a per-machine copy. Read it with and without the flag to see which copy has your value. - Settings and Terminal disagree. Reopen System Settings. If it shows a different state, make the change there once, then read the key again to see what Apple writes.
That last step is a reliable technique for any key you are unsure about. Read the domain, change the setting in System Settings, and read the domain again. The key that changed is the one macOS uses.
defaults read com.apple.AppleMultitouchTrackpad > before.txt
# change one setting in System Settings, then:
defaults read com.apple.AppleMultitouchTrackpad > after.txt
diff before.txt after.txtLimits to keep in mind
- Keys are not guaranteed to stay the same across macOS releases.
- Managed Macs may have settings enforced by a configuration profile. Your
defaults writecan succeed and still be overridden. - Preferences do not fix hardware or software faults. If a gesture fails entirely, the troubleshooting chapter covers the next steps.
Exercise
You run defaults read com.apple.AppleMultitouchTrackpad Clicking on a new Mac and get an error that the domain and default pair does not exist. Does this mean tap to click is broken, and how would you check the current state?
Show answer
No. The error means the key has never been stored, so macOS is using its built-in default, which is tap to click off. To check the current state, look at the Trackpad pane in System Settings. You can also change the setting there once and read the key again. A value of 1 or 0 should now appear.
Exercise
Write the commands to back up the built-in trackpad domain, turn on three-finger drag, and then remove only that one key if you change your mind. Assume the key is TrackpadThreeFingerDrag and its type is boolean.
Show answer
defaults export com.apple.AppleMultitouchTrackpad ~/trackpad-backup.plist defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerDrag -bool true defaults delete com.apple.AppleMultitouchTrackpad TrackpadThreeFingerDrag The delete command names the key, so the rest of the domain is untouched.
Exercise
You wrote defaults write NSGlobalDomain com.apple.trackpad.scaling -int 3 and the pointer speed did not change. Give two likely causes.
Show answer
First, the key is stored as a float, so the value should be written with -float, for example -float 3. Second, the change may not apply until you log out and log back in. Running defaults read-type on the key before writing would have revealed the type.