Skip to content

Instantly share code, notes, and snippets.

@jeffrafter
Last active December 26, 2022 15:56
Show Gist options
  • Save jeffrafter/71d994acb35529744e62772704e8fa4e to your computer and use it in GitHub Desktop.
Save jeffrafter/71d994acb35529744e62772704e8fa4e to your computer and use it in GitHub Desktop.
Setup a new Macbook
#!/usr/bin/env bash
# Based on ~/.macos — https://mths.be/macos
set -e
# Close any open System Preferences panes, to prevent them from overriding
# settings we’re about to change
osascript -e 'tell application "System Preferences" to quit'
echo ''
info () {
printf "\033[00;34m$1\033[0m\n"
}
user () {
printf "\033[0;33m$1\033[0m: "
}
success () {
printf "\033[00;32m$1\033[0m\n"
}
fail () {
printf "\n\033[2K[\033[0;31mX\033[0m] $1\n"
exit 1
}
# Set OS X defaults
info "Some of these settings will require sudo"
###############################################################################
# General UI/UX #
###############################################################################
user "What is your computer name? (e.g. $(scutil --get ComputerName))"
read -e osx_computer_name
user "What is your computer host name? (e.g. $(scutil --get HostName))"
read -e osx_computer_host_name
# Set computer name (as done via System Preferences → Sharing)
sudo scutil --set ComputerName $osx_computer_name
sudo scutil --set HostName $osx_computer_host_name
sudo scutil --set LocalHostName $osx_computer_host_name
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $osx_computer_host_name
success "Host names set"
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
success "Reveal IP address, hostname, OS version, etc. when clicking the clock in the login window"
sudo nvram SystemAudioVolume=" "
success "Disable the sound effects on boot"
defaults write com.apple.menuextra.battery ShowPercent -string "NO"
defaults write com.apple.menuextra.battery ShowTime -string "YES"
success "Show remaining battery time (on pre-10.8); hide percentage in the menu bar"
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001
success "Increase window resize speed for Cocoa applications"
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
success "Automatically quit printer app once the print jobs complete"
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
success "Display ASCII control characters using caret notation in standard text views"
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
success "Check for software updates daily, not just once per week"
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false
success "Disable automatic capitalization as it’s annoying when typing code"
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
success "Disable smart dashes as they’re annoying when typing code"
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false
success "Disable automatic period substitution as it’s annoying when typing code"
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
success "Disable smart quotes as they’re annoying when typing code"
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
success "Disable auto-correct"
defaults write -g WebAutomaticTextReplacementEnabled -bool false
success "Disable text-replacement"
###############################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
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
success "Enable tap to click for this user and for the login screen"
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
success "Increase sound quality for Bluetooth headphones/headsets"
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
success "Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)"
echo -n 'a' | sudo tee /private/var/db/.AccessibilityAPIEnabled > /dev/null 2>&1
sudo chmod 444 /private/var/db/.AccessibilityAPIEnabled
success "Enable access for assistive devices (used by AppleScript for GUI access)"
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
success "Disable press-and-hold for keys in favor of key repeat"
defaults write NSGlobalDomain KeyRepeat -int 0
defaults write -g KeyRepeat -int 1
success "Set a blazingly fast keyboard repeat rate"
defaults write com.apple.BezelServices kDim -bool true
success "Automatically illuminate built-in MacBook keyboard in low light"
defaults write com.apple.BezelServices kDimTime -int 300
success "Turn off keyboard illumination when computer is not used for 5 minutes"
###############################################################################
# Screen #
###############################################################################
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
success "Require password immediately after sleep or screen saver begins"
defaults write com.apple.screencapture location -string "$HOME/Desktop"
success "Save screenshots to the desktop"
defaults write com.apple.screencapture type -string "png"
success "Save screenshots in PNG format"
defaults write NSGlobalDomain AppleFontSmoothing -int 2
success "Enable subpixel font rendering on non-Apple LCDs"
# Enable HiDPI display modes (requires restart), should be default in retina macs
# sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
###############################################################################
# Finder #
###############################################################################
defaults write com.apple.finder QuitMenuItem -bool true
success "Allow quitting Finder via ⌘ + Q; doing so will also hide desktop icons"
# Finder: disable window animations and Get Info animations
# defaults write com.apple.finder DisableAllAnimations -bool true
# Show icons for hard drives, servers, and removable media on the desktop
# defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
# defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
# defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
# defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
defaults write com.apple.finder AppleShowAllFiles -bool true
success "Show hidden files by default"
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
success "Show all filename extensions in Finder"
defaults write com.apple.finder ShowStatusBar -bool true
success "Show the status bar in Finder"
defaults write com.apple.finder ShowPathBar -bool true
success "Show the path bar in Finder"
defaults write com.apple.finder QLEnableTextSelection -bool true
success "Allow text selection in Quick Look"
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
success "Display full path as Finder window title"
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
success "When performing a search, search the current folder by default"
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
success "Disable the warning when changing a file extension"
defaults write NSGlobalDomain com.apple.springing.enabled -bool true
success "Enable spring loading for directories"
defaults write NSGlobalDomain com.apple.springing.delay -float 0
success "Remove the spring loading delay for directories"
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
success "Avoid creating .DS_Store files on network volumes"
# defaults write com.apple.frameworks.diskimages skip-verify -bool true
# defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true
# defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true
# success "Disable disk image verification"
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true
success "Automatically open a new Finder window when a volume is mounted"
defaults write com.apple.finder EmptyTrashSecurely -bool true
success "Empty Trash securely by default"
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
success "Enable AirDrop over Ethernet and on unsupported Macs running Lion"
chflags nohidden ~/Library
success "Show the ~/Library folder"
sudo chflags nohidden /Volumes
success "Show the /Volumes folder"
defaults write com.apple.dock autohide-delay -float 0
success "Remove the auto-hiding Dock delay"
defaults write com.apple.dock autohide-time-modifier -float 0
success "Remove the animation when hiding/showing the Dock"
defaults write com.apple.dock autohide -bool true
success "Automatically hide and show the Dock"
defaults write com.apple.dock showhidden -bool true
success "Make Dock icons of hidden applications translucent"
# Add a spacer to the left side of the Dock (where the applications are)
# defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
# Add a spacer to the right side of the Dock (where the Trash is)
# defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'
# Hot corners
# Possible values:
# 0: no-op
# 2: Mission Control
# 3: Show application windows
# 4: Desktop
# 5: Start screen saver
# 6: Disable screen saver
# 7: Dashboard
# 10: Put display to sleep
# 11: Launchpad
# 12: Notification Center
# Top left screen corner
defaults write com.apple.dock wvous-tl-corner -int 0
defaults write com.apple.dock wvous-tl-modifier -int 0
# Top right screen corner
defaults write com.apple.dock wvous-tr-corner -int 0
defaults write com.apple.dock wvous-tr-modifier -int 0
# Bottom left screen corner
defaults write com.apple.dock wvous-bl-corner -int 0
defaults write com.apple.dock wvous-bl-modifier -int 0
# Bottom right screen corner
defaults write com.apple.dock wvous-br-corner -int 0
defaults write com.apple.dock wvous-br-modifier -int 0
success "Disable hot corner actions"
# Add iOS & Watch Simulator to Launchpad
sudo ln -sf "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app" "/Applications/Simulator.app"
sudo ln -sf "/Applications/Xcode.app/Contents/Developer/Applications/Simulator (Watch).app" "/Applications/Simulator (Watch).app"
###############################################################################
# Safari & WebKit #
###############################################################################
defaults write com.apple.Safari UniversalSearchEnabled -bool false
defaults write com.apple.Safari SuppressSearchSuggestions -bool true
success "Privacy: don’t send search queries to Apple"
defaults write com.apple.Safari HomePage -string "about:blank"
success "Set Safari’s home page to \"about:blank\" for faster loading"
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
success "Show the full URL in the address bar (note: this still hides the scheme)"
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
success "Prevent Safari from opening ‘safe’ files automatically after downloading"
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true
success "Enable the Develop menu and the Web Inspector in Safari"
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
success "Add a context menu item for showing the Web Inspector in web views"
defaults write com.apple.Safari WebContinuousSpellCheckingEnabled -bool true
success "Enable continuous spellchecking in Safari"
defaults write com.apple.Safari WebAutomaticSpellingCorrectionEnabled -bool false
success "Disable auto-correct in Safari"
defaults write com.apple.Safari WarnAboutFraudulentWebsites -bool true
success "Warn about fraudulent websites"
# defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true
# success "Enable “Do Not Track”"
###############################################################################
# Mail #
###############################################################################
# Disable send and reply animations in Mail.app
# defaults write com.apple.mail DisableReplyAnimations -bool true
# defaults write com.apple.mail DisableSendAnimations -bool true
defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false
success "Copy email addresses as 'foo@example.com' instead of 'Foo Bar <foo@example.com>' in Mail.app"
# Add the keyboard shortcut ⌘ + Enter to send an email in Mail.app
# defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Send" "@\\U21a9"
###############################################################################
# Terminal #
###############################################################################
defaults write com.apple.terminal StringEncodings -array 4
success "Only use UTF-8 in Terminal.app"
###############################################################################
# Address Book, Dashboard, iCal, TextEdit, and Disk Utility #
###############################################################################
defaults write com.apple.TextEdit RichText -int 0
success "Use plain text mode for new TextEdit documents"
defaults write com.apple.TextEdit PlainTextEncoding -int 4
defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
success "Open and save files as UTF-8 in TextEdit"
defaults write com.apple.DiskUtility DUDebugMenuEnabled -bool true
defaults write com.apple.DiskUtility advanced-image-options -bool true
success "Enable the debug menu in Disk Utility"
###############################################################################
# Google Chrome & Google Chrome Canary #
###############################################################################
defaults write com.google.Chrome ExtensionInstallSources -array "https://*.github.com/*" "http://userscripts.org/*"
defaults write com.google.Chrome.canary ExtensionInstallSources -array "https://*.github.com/*" "http://userscripts.org/*"
success "Allow installing user scripts via GitHub or Userscripts.org"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment