Last active
July 29, 2023 19:24
-
-
Save mdemerson/7e614b75fc6e4657854e5f91bcc176a5 to your computer and use it in GitHub Desktop.
Some macOS defaults I set on any new system/VM that I have to use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
################################################################################ | |
# # | |
# macOS Preferences Defaults # | |
# By Mat Emerson # | |
# # | |
################################################################################ | |
# # | |
# Some macOS defaults I set on any new system/VM that I have to use. # | |
# Current version working on MacOS 11 (Big Sur) to MacOS 13 (Ventura) # | |
# Updated 23rd of Jan 2023 # | |
# # | |
################################################################################ | |
# # | |
# Inspired by the macOS defaults files of: # | |
# Christopher Allen - https://github.com/christophera/ # | |
# Mathias Bynens - https://github.com/mathiasbynens/dotfiles # | |
# Kevin Suttle - https://github.com/kevinSuttle/macOS-Defaults # | |
# # | |
################################################################################ | |
####################################################################################################### | |
# # | |
# To bootstrap, the following curl command will download this script and run it: # | |
# curl -L https://gist.githubusercontent.com/mdemerson/7e614b75fc6e4657854e5f91bcc176a5/raw | bash # | |
# # | |
# Whilst scripts can be useful, they can also be malicious. Ensure that you understand # | |
# what a script will do before running it. Run only scripts that you trust. # | |
# # | |
####################################################################################################### | |
# Before we go any further... | |
## Make sure we're in macOS, no point continuing otherwise. | |
if [[ ! "$OSTYPE" == "darwin"* ]]; then | |
echo "This script is for macOS, you don't appear to be on macOS, exiting script." | |
exit 1 | |
fi | |
################################################################################ | |
# # | |
# Variables # | |
# # | |
################################################################################ | |
# Computer/machine name | |
computername="matbookair" | |
# Backup Stuff | |
backuproot="$HOME/Backups" | |
backupfile="plistbackup-$(date +'%s').tar" | |
backuppath="$backuproot/$backupfile" | |
## Mac Hardware Model | |
osx_hardware_model=$(sysctl -n hw.model) | |
## Cpu info | |
cpu_hardware_model=$(sysctl -n machdep.cpu.brand_string) | |
cpu_hardware_cores=$(sysctl -n machdep.cpu.core_count) | |
## Which version and build of macOS are we executing under? | |
read -r osx_product_version osx_vers_major osx_vers_minor osx_vers_patch \ | |
<<< "$(sw_vers -productVersion | awk -F. '{print $0 " " $1 " " $2 " " $3}')" | |
osx_build_version="$(sw_vers -buildVersion)" | |
## What is the friendly name for this machine's macOS version? | |
case "$osx_product_version" in | |
"10.4"*) osx_codename="Mac OS X Tiger" ;; | |
"10.5"*) osx_codename="Mac OS X Leopard" ;; | |
"10.6"*) osx_codename="Mac OS X Snow Leopard" ;; | |
"10.7"*) osx_codename="Mac OS X Lion" ;; | |
"10.8"*) osx_codename="OS X Mountain Lion" ;; | |
"10.9"*) osx_codename="OS X Mavericks" ;; | |
"10.10"*) osx_codename="OS X Yosemite" ;; | |
"10.11"*) osx_codename="OS X El Capitan" ;; | |
"10.12"*) osx_codename="macOS Sierra" ;; | |
"10.13"*) osx_codename="macOS High Sierra" ;; | |
"10.14"*) osx_codename="macOS Mojave" ;; | |
"10.15"*) osx_codename="macOS Catalina" ;; | |
"11."*) osx_codename="macOS Big Sur" ;; | |
"12."*) osx_codename="macOS Monterey" ;; | |
"13."*) osx_codename="MacOS Ventura" ;; | |
*) osx_codename="macOS" ;; | |
esac | |
osx_distro="$osx_codename $osx_product_version (build $osx_build_version)" | |
# Plists to backup | |
pliststobackup=( | |
"com.apple.dock" | |
"com.apple.finder" | |
"com.apple.screencapture" | |
"com.apple.NetworkBrowser" | |
"NSGlobalDomain" | |
"com.apple.desktopservices" | |
"com.apple.frameworks.diskimages" | |
"com.apple.Safari" | |
"com.apple.spaces.plist" | |
) | |
################################################################################ | |
# # | |
# Initial Setup # | |
# # | |
################################################################################ | |
# Ask for the sudo powers and keep sudo alive | |
sudo -v | |
while true; do | |
sudo -n true | |
sleep 60 | |
kill -0 "$$" || exit 0 | |
done 2>/dev/null & | |
# Close any open System Preferences windows | |
osascript -e 'tell application "System Preferences" to quit' | |
# Set host, localhost, and computer names | |
if [ -n "$computername" ]; then | |
sudo scutil --set HostName "$computername" | |
sudo scutil --set LocalHostName "$computername" | |
sudo scutil --set ComputerName "$computername" | |
fi | |
# Backup Plists | |
mkdir -p "$backuproot" | |
for plist in "${pliststobackup[@]}"; do | |
echo "Backing up $plist" | |
defaults read "$plist" > "$HOME/$plist.txt" | |
tar vrf "$backuppath" "$HOME/$plist.txt" > /dev/null 2>&1 | |
rm "$HOME/$plist.txt" | |
done | |
## Output system info to user | |
printf "Running %s on a %s.\n" "$osx_distro" "$osx_hardware_model" | |
printf "system has a %s CPU, with %s Cores\n" "$cpu_hardware_model" "$cpu_hardware_cores" | |
printf "\n\nOptimising defaults..." | |
################################################################################ | |
# # | |
# Global # | |
# # | |
################################################################################ | |
# Set language and text formats | |
defaults write NSGlobalDomain AppleLanguages -array "en" "au" | |
defaults write NSGlobalDomain AppleLocale -string "en_AU@currency=AUD" | |
defaults write NSGlobalDomain AppleMeasurementUnits -string "Centimeters" | |
defaults write NSGlobalDomain AppleMetricUnits -bool true | |
# Save to disk (not to iCloud) by default | |
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false | |
# Disable Resume globally | |
defaults write com.apple.systempreferences NSQuitAlwaysKeepsWindows -bool false | |
## Disable "Natural" Scrolling on trackpad | |
defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false | |
## Set Key repeat Speed | |
defaults write NSGlobalDomain KeyRepeat -int 1 | |
## Disable Automatic Spelling correction | |
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false | |
## Disable automatic capitalisation | |
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false | |
# Disable "smart" dashes | |
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false | |
## Disable "smart" quotes | |
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false | |
## Disable "Add period on double space" | |
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false | |
## Show file extension in finder | |
defaults write NSGlobalDomain AppleShowAllExtensions -bool true | |
## Set menu bar to auto hide | |
defaults write NSGlobalDomain _HIHideMenuBar -bool true | |
## Set interface to dark | |
defaults write NSGlobalDomain AppleInterfaceStyle -string "Dark" | |
## Set hilight colour to Light green | |
defaults write NSGlobalDomain AppleHighlightColor -string "0.698039 0.843137 1.000000 Blue" | |
## Turn on accent hilighting, select blue | |
defaults write NSGlobalDomain AppleAccentColor -string 4 | |
## Increase the speed of dialogs boxes | |
defaults write NSGlobalDomain NSWindowResizeTime -float .1 | |
## Disable press-and-hold symbol keys | |
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false | |
## Disable window animations | |
# defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false | |
## Allow windows to span across spaces | |
# defaults write com.apple.spaces spans-displays -bool false | |
## Spring loaded directories | |
defaults write NSGlobalDomain com.apple.springing.enabled -bool true | |
## Delay for spring loaded directories | |
defaults write NSGlobalDomain com.apple.springing.delay -float 0.3 | |
## Disable writing of .DS_Store files on network or USB volumes | |
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true | |
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true | |
## Set sidebar icon size to medium | |
defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 2 | |
## Always expand save panel | |
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true | |
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true | |
## Always expand print panel | |
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true | |
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true | |
################################################################################ | |
# # | |
# Activity Monitor # | |
# # | |
################################################################################ | |
# Show the main window when launching Activity Monitor | |
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true | |
# Visualize CPU usage in the Activity Monitor Dock icon | |
defaults write com.apple.ActivityMonitor IconType -int 5 | |
# Show all processes in Activity Monitor | |
defaults write com.apple.ActivityMonitor ShowCategory -int 0 | |
# Sort Activity Monitor results by CPU usage | |
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage" | |
defaults write com.apple.ActivityMonitor SortDirection -int 0 | |
################################################################################ | |
# # | |
# Application Specific # | |
# # | |
################################################################################ | |
# Don’t display a prompt when quitting iTerm | |
defaults write com.googlecode.iterm2 PromptOnQuit -bool false | |
# Disable backswipe on trackpads in Google Chrome | |
defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false | |
defaults write com.google.Chrome.canary AppleEnableSwipeNavigateWithScrolls -bool false | |
# Disable backswipe on Magic Mouse in Google Chrome | |
defaults write com.google.Chrome AppleEnableMouseSwipeNavigateWithScrolls -bool false | |
defaults write com.google.Chrome.canary AppleEnableMouseSwipeNavigateWithScrolls -bool false | |
# Use the system-native print preview dialog in Google Chrome | |
defaults write com.google.Chrome DisablePrintPreview -bool true | |
defaults write com.google.Chrome.canary DisablePrintPreview -bool true | |
# Expand the print dialog by default in Google Chrome | |
defaults write com.google.Chrome PMPrintingExpandedStateForPrint2 -bool true | |
defaults write com.google.Chrome.canary PMPrintingExpandedStateForPrint2 -bool true | |
# Automatically quit printer app once print jobs complete. | |
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true | |
## Set screenshots to save to nextcloud directory (Check dir exists first) | |
[ -d "$HOME/Nextcloud/Pictures/Screenshots" ] && defaults write com.apple.screencapture location -string "$HOME/Nextcloud/Pictures/Screenshots" | |
## Turn off Screenshot shadows | |
defaults write com.apple.screencapture disable-shadow -bool true | |
## Set screenshots to .png format | |
defaults write com.apple.screencapture type -string "png" | |
################################################################################ | |
# # | |
# Bluetooth # | |
# # | |
################################################################################ | |
# Increase sound quality for Bluetooth headphones/headsets | |
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40 | |
################################################################################ | |
# # | |
# Disk Operation # | |
# # | |
################################################################################ | |
## Skip disk image verification | |
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 | |
## unhide the User Library Folder | |
chflags nohidden ~/Library/ | |
################################################################################ | |
# # | |
# Dock # | |
# # | |
################################################################################ | |
## Put the Dock on left of screen. | |
defaults write com.apple.dock orientation -string "left" | |
## Set the icon size of Dock items to 27 pixels | |
defaults write com.apple.dock tilesize -int 27 | |
## Show only active apps on dock | |
defaults write com.apple.dock static-only -bool true | |
## Autohide Dock | |
defaults write com.apple.dock autohide -bool true | |
## Speed up Dock hiding (instant) | |
defaults write com.apple.dock autohide-time-modifier -float 0 | |
## Speed up Dock unhide (instant) | |
defaults write com.apple.dock autohide-delay -float 0 | |
## Make hidden apps appear translucent in Dock | |
defaults write com.apple.dock showhidden -bool true | |
## Don't show recent items in Dock | |
defaults write com.apple.dock show-recents -bool false | |
# Set window minimise effect to "scale" | |
defaults write com.apple.dock mineffect -string "scale" | |
################################################################################ | |
# # | |
# Finder # | |
# # | |
################################################################################ | |
## Enable text selection in Quick Look | |
defaults write com.apple.finder QLEnableTextSelection -bool true | |
## Show hidden files in finder | |
defaults write com.apple.finder AppleShowAllFiles -bool true | |
## Hide desktop icons | |
defaults write com.apple.finder CreateDesktop -bool false | |
## Turn off "You're changing a file extension" warning | |
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false | |
## Use current directory as search scope when using finder | |
# This Mac : `SCev` | |
# Current Folder : `SCcf` | |
# Previous Scope : `SCsp` | |
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf" | |
## Display posix path in finder window title | |
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true | |
## Finder defaults to column view | |
# Icon View : `icnv` | |
# List View : `Nlsv` | |
# Column View : `clmv` | |
# Cover Flow : `Flwv` | |
defaults write com.apple.finder FXPreferredViewStyle -string "clmv" | |
## Add finder quit option | |
defaults write com.apple.finder QuitMenuItem -bool true | |
## Disable all finder 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 false | |
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false | |
defaults write com.apple.finder ShowMountedServersOnDesktop -bool false | |
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false | |
# Show path bar | |
defaults write com.apple.finder ShowPathbar -bool true | |
# Arrange by: | |
# Kind, Name, Application, Date Last Opened, | |
# Date Added, Date Modified, Date Created, Size, Tags, None | |
defaults write com.apple.finder FXPreferredGroupBy -string "Name" | |
## Keep folders on top when sorting by name | |
defaults write com.apple.finder _FXSortFoldersFirst -bool true | |
## New window start folder | |
# Computer : `PfCm` | |
# Volume : `PfVo` | |
# $HOME : `PfHm` | |
# Desktop : `PfDe` | |
# Documents : `PfDo` | |
# All My Files : `PfAF` | |
# Other… : `PfLo` | |
defaults write com.apple.finder NewWindowTarget -string 'PfHm' | |
## Disable warning before emptying Trash | |
defaults write com.apple.finder WarnOnEmptyTrash -bool false | |
## Empty Trash securely by default | |
defaults write com.apple.finder EmptyTrashSecurely -bool true | |
## Expand the following File Info panes: | |
# “General”, “Open with”, and “Sharing & Permissions” | |
defaults write com.apple.finder FXInfoPanesExpanded -dict \ | |
General -bool true \ | |
OpenWith -bool true \ | |
Privileges -bool true | |
## Don't automatically open a new Finder window when a volume is mounted | |
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool false | |
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool false | |
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool false | |
################################################################################ | |
# # | |
# 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 | |
## Bottom left screen corner → Start screen saver | |
# defaults write com.apple.dock wvous-bl-corner -int 10 # sleep display | |
# defaults write com.apple.dock wvous-bl-modifier -int 0 | |
################################################################################ | |
# # | |
# Mac app store # | |
# # | |
################################################################################ | |
# Install System data files & security updates | |
defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 1 | |
# Download newly available updates in background | |
# defaults write com.apple.SoftwareUpdate AutomaticDownload -int 1 | |
# Turn on app auto-update | |
# defaults write com.apple.commerce AutoUpdate -bool true | |
# Allow the App Store to reboot machine on macOS updates | |
# defaults write com.apple.commerce AutoUpdateRestartRequired -bool true | |
################################################################################ | |
# # | |
# Messages # | |
# # | |
################################################################################ | |
# Disable automatic emoji substitution (i.e. use plain text smileys) | |
# defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticEmojiSubstitutionEnablediMessage" -bool false | |
# Disable smart quotes as it’s annoying for messages that contain code | |
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticQuoteSubstitutionEnabled" -bool false | |
# Disable continuous spell checking | |
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "continuousSpellCheckingEnabled" -bool false | |
################################################################################ | |
# # | |
# Mission Control # | |
# # | |
################################################################################ | |
## Speed up Mission Control animations | |
defaults write com.apple.dock expose-animation-duration -float 0.12 | |
################################################################################ | |
# # | |
# Network # | |
# # | |
################################################################################ | |
## Allow airdrop on wired network | |
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true | |
################################################################################ | |
# # | |
# Notifications and Prompts # | |
# # | |
################################################################################ | |
# Get rid of "You didn't unplug this properly" notifications | |
# defaults write /Library/Preferences/SystemConfiguration/com.apple.DiskArbitration.diskarbitrationd.plist \ | |
# DADisableEjectNotification -bool true | |
# To get the "You didn't unplug this properly" notifications back | |
# defaults delete /Library/Preferences/SystemConfiguration/com.apple.DiskArbitration.diskarbitrationd.plist \ | |
# DADisableEjectNotification | |
# Disable Notification Center and remove the menu bar icon | |
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null | |
# Disable the “Are you sure you want to open this application?” dialog | |
defaults write com.apple.LaunchServices LSQuarantine -bool false | |
################################################################################ | |
# # | |
# Safari # | |
# # | |
################################################################################ | |
## Show hovering overlay on links | |
defaults write com.apple.Safari ShowOverlayStatusBar -bool true | |
## Safari opens with: last session | |
defaults write com.apple.Safari AlwaysRestoreSessionAtLaunch -bool false | |
## Safari should open with a blank window | |
# 0: Home page | |
# 1: Empty Page | |
# 2: Same Page | |
# 4: Start Page | |
# 5: Tabs for Favourites | |
defaults write com.apple.Safari NewWindowBehavior -int 1 | |
# Enable Safari Debug menu | |
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true | |
# Enable “Do Not Track” | |
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true | |
# Update extensions automatically | |
defaults write com.apple.Safari InstallExtensionUpdatesAutomatically -bool true | |
################################################################################ | |
# # | |
# Spaces # | |
# # | |
################################################################################ | |
## Don't Rearrange spaces automatically | |
defaults write com.apple.dock mru-spaces -bool false | |
################################################################################ | |
# # | |
# Spotlight # | |
# # | |
################################################################################ | |
# 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 /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes" | |
# Make sure indexing is enabled for the root volume | |
sudo mdutil -i on / > /dev/null | |
################################################################################ | |
# # | |
# Time Machine # | |
# # | |
################################################################################ | |
# Prevent Time Machine from prompting to use new hard drives as backup volume | |
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true | |
# Disable local Time Machine backups | |
hash tmutil &> /dev/null && sudo tmutil disable local | |
################################################################################ | |
# # | |
# Finish up # | |
# # | |
################################################################################ | |
# Restart apps that may have been affected | |
for app in "Activity Monitor" \ | |
"Address Book" \ | |
"Calendar" \ | |
"cfprefsd" \ | |
"diskarbitrationd" \ | |
"Dock" \ | |
"Finder" \ | |
"Google Chrome" \ | |
"Mail" \ | |
"Messages" \ | |
"Photos" \ | |
"Safari" \ | |
"SystemUIServer" \ | |
"App Store" \ | |
"iCal"; do | |
killall "${app}" &> /dev/null | |
done | |
echo "All done..." | |
echo "You should run 'sudo find / -name \".DS_Store\" -delete' and then reboot to finish up." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment