Preferences changes using "defaults" not applied
I'm a CLI enthusiast and, as such, I've been a extensive user of brew, cask, m, mas, softwareupdate and so on. I've even written some tutorials about them (check here and there).
Right now, I'm diving into defaults to alter my settings.
My problem is that some defaults set in CLI don't appear in GUI. For instance, I try to deactivate "three fingers lookup & data detectors" in System Preferences > Trackpad
Using diff and defaults read, I found that the settings is "TrackpadThreeFingerTapGesture" in "com.apple.AppleMultitouchTrackpad".
When the checkbox is checked, "defaults read com.apple.AppleMultitouchTrackpad TrackpadThreeFingerTapGesture" returns 2. That's the default value. When it's no checked, it returns 0. That's what I want.
To test this out, I checked the setting in the GUI, then used these commands:
killall 'System Preferences'
defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerTapGesture -int 0
defaults read com.apple.AppleMultitouchTrackpad TrackpadThreeFingerTapGesture
The last commands returns 0, which is ok. But when I open the GUI, the checkbox is still checked! Reading the value again still gives me 0...
I even tried logging out after altering the value, the problem remains.
Can someone help?
The preference you wish to set is saved in ~/Library/Preferences/ByHost
, so you have to add the switch -currentHost
to the defaults
command
Try the following code with Value
set to 0
, then set to 2
and see the difference
Value="0"; \
echo "before"; \
: read actual values; \
defaults -currentHost read -g "com.apple.trackpad.threeFingerTapGesture"; \
defaults read com.apple.AppleMultitouchTrackpad TrackpadThreeFingerTapGesture; \
: close System Preferenes; \
pkill -u "${USER}" \
-f "^/Applications/System Preferences.app/Contents/MacOS/System Preferences$" 2>/dev/null; \
: set value in ~/Library/Preferences/ByHost/.GlobalPreferences.#Hardware UUID#.plist; \
: where your hardware uuid can be determined with; \
: ioreg -c IOPlatformExpertDevice -d 2 | awk -F'"' '/IOPlatformUUID/ { print $(NF-1) }'; \
defaults -currentHost write -g "com.apple.trackpad.threeFingerTapGesture" -integer ${Value}; \
: set value in ~/Library/Preferences/.GlobalPreferences.plist; \
defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerTapGesture -integer ${Value}; \
: kill the preference cache process; \
pkill -u "${USER}" -l "^/usr/sbin/cfprefsd agent$" 2>/dev/null; \
: wait a second otherwise you get errors on the defaults commands; \
sleep 1; \
echo "after"; \
: read set values; \
defaults -currentHost read -g "com.apple.trackpad.threeFingerTapGesture"; \
defaults read com.apple.AppleMultitouchTrackpad TrackpadThreeFingerTapGesture; \
: open trackpad preference; \
open "/System/Library/PreferencePanes/Trackpad.prefPane"
gives me
before
2
2
after
0
0
regards
Gerd