all repos — dot @ ed21d1270007a8f9cbaa2ca7da0fee1eefeb405f

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
#!/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"

# Menubar date format
defaults write com.apple.menuextra.clock "DateFormat" -string "\"HH:mm\""

# Three finger trackpad drag
defaults write com.apple.AppleMultitouchTrackpad "TrackpadThreeFingerDrag" -bool "true"

# 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