all repos — dot @ fac95146b95ef103e8100b2284671be4bdc1065f

Shell, editor and terminal configuration, and the tools that go with them

macos-defaults.sh (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
#!/bin/bash

# The baseline settings every new Mac starts from: Finder, Dock, keyboard,
# trackpad, menu-bar clock, Spotlight. Run it once, when setting a Mac up:
#
#   ~/src/soarez/dot/macos-defaults.sh
#
# A private layer's bootstrap may run it on a new Mac; install.sh points to it
# otherwise. Nothing runs it on its own, and nothing should: it
# replaces the Dock with the three apps below and restarts Finder and the Dock.
# A Mac is free to drift from these afterwards; this is where it starts, not a
# state kept in sync. Asks for sudo, for the Spotlight setting.
#
# Reference: https://macos-defaults.com/

set -euo pipefail

if [[ "$(uname)" != "Darwin" ]]; then
    >&2 echo "ERROR: macOS only"
    exit 1
fi

# Show hidden files, filename extensions, full path & disable extension warning
defaults write com.apple.finder "AppleShowAllFiles" -bool "true"
defaults write NSGlobalDomain "AppleShowAllExtensions" -bool "true"
defaults write com.apple.finder "ShowPathbar" -bool "true"
defaults write com.apple.finder "FXEnableExtensionChangeWarning" -bool "false"

# Set list view as default Finder view
defaults write com.apple.finder "FXPreferredViewStyle" -string "Nlsv"

# Set Dock size, autohide, recents
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\""

# 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)
defaults write ~/Library/Preferences/com.apple.HIToolbox.plist 'AppleFnUsageType' -int 0
defaults write -g ApplePressAndHoldEnabled 0

# Use thin strokes
defaults -currentHost write -g AppleFontSmoothing -int 0
# defaults -currentHost delete -g AppleFontSmoothing

# Set dock apps: the app launcher, Alacritty, iPhone Mirroring. The launcher is
# Launchpad up to macOS 15; macOS 26 has no Launchpad and calls it Apps.
launcher=/System/Applications/Launchpad.app
if [[ ! -e "${launcher}" ]]; then
    launcher=/System/Applications/Apps.app
fi
defaults delete com.apple.dock persistent-apps
dock_item() {
    printf '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>%s</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>' "$1"
}
defaults write com.apple.dock persistent-apps -array \
    "$(dock_item "${launcher}")" \
    "$(dock_item /Applications/Alacritty.app)" \
    "$(dock_item '/System/Applications/iPhone Mirroring.app')"

# Disable Spotlight indexing for any volume that gets mounted and has not yet
# been indexed before.
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
sudo defaults write /Library/Preferences/com.apple.SpotlightServer.plist ExternalVolumesIgnore -bool true

# Restart stuff
killall Finder
killall Dock