#!/usr/bin/env bash
# macos/defaults.sh -- one-shot script I run on a fresh macOS. Groups the
# tweaks by domain so I can comment out what I no longer care about. The
# script is idempotent; re-running it just re-asserts everything.
set -euo pipefail
if [[ $(uname -s) != "Darwin" ]]; then
print "defaults.sh: only useful on macOS, skipping." >&2
exit 0
fi
say() { printf '\n[%s] %s\n' "$(date +%H:%M:%S)" "$*"; }
say "asking for sudo up front"
sudo -v
# -----------------------------------------------------------------------------
# General UI / UX
# -----------------------------------------------------------------------------
defaults write -g AppleShowScrollBars -string "Always"
defaults write -g AppleScrollerPagingBehavior -bool true
defaults write -g NSAutomaticCapitalizationEnabled -bool false
defaults write -g NSAutomaticDashSubstitutionEnabled -bool false
defaults write -g NSAutomaticPeriodSubstitutionEnabled -bool false
defaults write -g NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false
# Subpixel antialiasing gave better kerning on non-retina panels. On modern
# macOS it is a no-op but I keep the line because it documents intent.
defaults write -g AppleFontSmoothing -int 1
# Faster key repeat. Requires logout to take effect.
defaults write -g InitialKeyRepeat -int 15
defaults write -g KeyRepeat -int 2
# -----------------------------------------------------------------------------
# Finder
# -----------------------------------------------------------------------------
defaults write com.apple.finder AppleShowAllFiles -bool true
defaults write com.apple.finder ShowPathbar -bool true
defaults write com.apple.finder ShowStatusBar -bool true
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf" # current folder
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv" # list view
defaults write com.apple.finder FXRemoveOldTrashItems -bool true
defaults write -g AppleShowAllExtensions -bool true
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# -----------------------------------------------------------------------------
# Dock
# -----------------------------------------------------------------------------
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock autohide-delay -float 0
defaults write com.apple.dock autohide-time-modifier -float 0.15
defaults write com.apple.dock tilesize -int 38
defaults write com.apple.dock mineffect -string "scale"
defaults write com.apple.dock show-recents -bool false
defaults write com.apple.dock orientation -string "left"
defaults write com.apple.dock static-only -bool true # only running apps
# -----------------------------------------------------------------------------
# Mission Control / Hot corners
# -----------------------------------------------------------------------------
defaults write com.apple.dock mru-spaces -bool false
defaults write com.apple.dock expose-group-apps -bool true
# Hot corners (tl tr bl br). 2=Mission Control, 10=Lock, 14=Quick Note.
defaults write com.apple.dock wvous-tl-corner -int 2
defaults write com.apple.dock wvous-tl-modifier -int 0
defaults write com.apple.dock wvous-br-corner -int 10
defaults write com.apple.dock wvous-br-modifier -int 0
# -----------------------------------------------------------------------------
# Screenshots
# -----------------------------------------------------------------------------
mkdir -p "$HOME/Pictures/Screenshots"
defaults write com.apple.screencapture location -string "$HOME/Pictures/Screenshots"
defaults write com.apple.screencapture type -string "png"
defaults write com.apple.screencapture disable-shadow -bool true
# -----------------------------------------------------------------------------
# Safari / web
# -----------------------------------------------------------------------------
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari HomePage -string "about:blank"
defaults write com.apple.Safari AutoFillFromAddressBook -bool false
# -----------------------------------------------------------------------------
# Terminal / iTerm / Input
# -----------------------------------------------------------------------------
defaults write com.apple.Terminal ShowLineMarks -bool false
defaults write -g ApplePressAndHoldEnabled -bool false # key repeat in editors
# -----------------------------------------------------------------------------
# Apply
# -----------------------------------------------------------------------------
say "killing affected apps so changes take effect"
for app in "Finder" "Dock" "SystemUIServer" "cfprefsd"; do
killall "$app" >/dev/null 2>&1 || true
done
say "done. Some tweaks need a logout."