diff options
| -rwxr-xr-x | bin/macos-defaults-diff | 99 | ||||
| -rwxr-xr-x | macos-defaults.sh | 20 |
2 files changed, 118 insertions, 1 deletions
diff --git a/bin/macos-defaults-diff b/bin/macos-defaults-diff new file mode 100755 index 0000000..14274e3 --- /dev/null +++ b/bin/macos-defaults-diff @@ -0,0 +1,99 @@ +#!/bin/bash + +# Find the `defaults` key behind a setting you changed in System Settings, so it +# can go in macos-defaults.sh instead of being remembered. +# +# macos-defaults-diff snapshot, wait while you change one setting, +# then print what moved +# macos-defaults-diff snap take the snapshot only +# macos-defaults-diff show compare now against the last snapshot +# +# It reads both the global domains and the per-host ones (`-currentHost`), which +# is where several trackpad, mouse and font settings live and which a plain +# `defaults read` never shows. +# +# Change ONE setting at a time. macOS writes unrelated keys constantly -- window +# positions, recent items, sidebar widths -- so a diff after three changes is +# mostly noise with your key hidden in it. +# +# Quit System Settings before the second snapshot. It holds changes in memory +# and cfprefsd may not have written them yet; the line below flushes that cache. +# +# Runs under macOS's /bin/bash 3.2. + +set -euo pipefail + +if [[ "$(uname)" != "Darwin" ]]; then + >&2 echo "macos-defaults-diff: macOS only" + exit 1 +fi + +dir="${TMPDIR:-/tmp}/macos-defaults-diff" +mkdir -p "${dir}" + +snapshot() { + local tag="$1" + # cfprefsd caches writes; without this a change made seconds ago can be + # missing from the read that is supposed to reveal it. + killall cfprefsd 2>/dev/null || true + sleep 1 + defaults read > "${dir}/${tag}.txt" 2>/dev/null || true + defaults -currentHost read > "${dir}/${tag}-host.txt" 2>/dev/null || true +} + +report() { + if [[ ! -f "${dir}/before.txt" ]]; then + >&2 echo "macos-defaults-diff: no snapshot yet -- run 'macos-defaults-diff snap' first" + exit 1 + fi + snapshot after + local found="" + if ! diff -u "${dir}/before.txt" "${dir}/after.txt" > "${dir}/delta.txt" 2>&1; then + found=y + echo "=== global domains" + grep -E '^[+-]' "${dir}/delta.txt" | grep -vE '^(\+\+\+|---)' | sed 's/^/ /' + fi + if ! diff -u "${dir}/before-host.txt" "${dir}/after-host.txt" > "${dir}/delta-host.txt" 2>&1; then + found=y + echo "=== this host only -- these need 'defaults -currentHost write'" + grep -E '^[+-]' "${dir}/delta-host.txt" | grep -vE '^(\+\+\+|---)' | sed 's/^/ /' + fi + if [[ -z "${found}" ]]; then + echo "nothing changed." + echo "Some settings are not in defaults at all: anything behind Privacy &" + echo "Security lives in the SIP-protected TCC database, and a few panes use" + echo "private APIs. Those cannot be scripted -- note them in macos-defaults.sh" + echo "as manual steps instead." + return + fi + echo + echo "The domain is the nearest heading above the changed line in:" + echo " ${dir}/delta.txt" + echo "Write it as: defaults write <domain> \"<key>\" -bool/-int/-string <value>" + echo "then add it to macos-defaults.sh, and restart whatever owns it" + echo "(killall Dock, killall Finder, or log out)." +} + +case "${1:-}" in + snap) + snapshot before + echo "snapshot taken. Change one setting, then: macos-defaults-diff show" + ;; + show) + report + ;; + "") + snapshot before + echo "Snapshot taken. Now change ONE setting in System Settings, quit it," + printf 'then press Enter: ' + read -r _ + report + ;; + -h|--help) + sed -n '3,21p' "$0" | sed 's/^# \{0,1\}//' + ;; + *) + >&2 echo "macos-defaults-diff: unknown argument: $1" + exit 1 + ;; +esac diff --git a/macos-defaults.sh b/macos-defaults.sh index c5830e8..c712069 100755 --- a/macos-defaults.sh +++ b/macos-defaults.sh @@ -34,11 +34,29 @@ defaults write com.apple.dock "tilesize" -int "46" defaults write com.apple.dock "autohide" -bool "true" defaults write com.apple.dock "show-recents" -bool "false" +# Hot corners. 10 puts the display to sleep; the modifier is the key that must +# be held, 0 for none. The others are left alone rather than set to "no action", +# so a machine that has its own is not overruled. Values: 2 Mission Control, +# 3 application windows, 4 desktop, 5 screen saver, 10 display sleep, +# 11 Launchpad, 12 Notification Centre, 13 lock screen, 14 quick note. +defaults write com.apple.dock "wvous-br-corner" -int 10 +defaults write com.apple.dock "wvous-br-modifier" -int 0 + # Menubar date format defaults write com.apple.menuextra.clock "DateFormat" -string "\"HH:mm\"" -# Three finger trackpad drag +# Trackpad. Each of these is written in more than one place, and all of them +# are needed: com.apple.AppleMultitouchTrackpad is the built-in trackpad, +# com.apple.driver.AppleBluetoothMultitouch.trackpad an external Magic Trackpad, +# and com.apple.mouse.tapBehavior is what the login window and new accounts +# read -- per-host for this Mac, global as the default for any host. defaults write com.apple.AppleMultitouchTrackpad "TrackpadThreeFingerDrag" -bool "true" +defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad "TrackpadThreeFingerDrag" -bool "true" + +defaults write com.apple.AppleMultitouchTrackpad "Clicking" -bool "true" +defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad "Clicking" -bool "true" +defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1 +defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1 # Keyboard settings # disable FN (globe key) |
