Skip to content

Instantly share code, notes, and snippets.

@janniks
Created December 10, 2020 12:05
Show Gist options
  • Save janniks/0c0e0e2ba7491ee122c55d37b36b0d43 to your computer and use it in GitHub Desktop.
Save janniks/0c0e0e2ba7491ee122c55d37b36b0d43 to your computer and use it in GitHub Desktop.
macOS setup script
#!/usr/bin/env bash
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
echo ""
echo "Download the official Dropbox app manually and sync relevant dotfiles"
echo "Press [Enter] to continue or [Ctrl-C] to cancel..."
read -p ""
echo ""
echo "Download the official 1Password app manually and sync from Dropbox"
echo "Press [Enter] to continue or [Ctrl-C] to cancel..."
read -p ""
echo ""
echo "Asking for the administrator password upfront"
sudo -v
if test ! -f ~/.ssh/id_rsa; then
echo "Creating an SSH key for you..."
ssh-keygen -t rsa
echo "Please add this public key to Github"
echo "https://github.com/account/ssh"
echo "Press [Enter] to continue or [Ctrl-C] to cancel..."
read -p ""
fi
echo ""
echo "Installing xcode-select"
xcode-select --install
if test ! $(which brew); then
echo ""
echo "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap homebrew/cask-fonts
fi
echo ""
echo "Updating homebrew..."
brew update
echo ""
echo "Installing brew essentials..."
brew install git gpg zsh wget tmux nvm pyenv hub autojump mackup
# install n manually later as system node
echo ""
echo "Installing Cask apps..."
apps=(
alfred
appcleaner
bartender
dash
discord
firefox
font-source-code-pro
google-chrome
itsycal
little-snitch
qlmarkdown
qlstephen
rectangle
skype
slack
spotify
sublime-text
transmission
visual-studio-code
)
# `--no-quarantine` allows apps to run as login items on startup
brew install --cask --no-quarantine --appdir="/Applications" ${apps[@]}
echo "Cleaning up brew"
brew cleanup
if test ! -d ~/.oh-my-zsh/; then
echo ""
echo "Installing Oh My ZSH..."
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
echo ""
echo "Open Alfred manually, sync with Dropbox, and set correct theme"
echo "Press [Enter] to continue or [Ctrl-C] to cancel..."
read -p ""
echo "Applying some common system preferences next..."
echo "Press [Enter] to continue or [Ctrl-C] to cancel..."
read -p ""
################################################################################
# General #
################################################################################
# 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'
# Disable the sound effects on boot
#sudo nvram SystemAudioVolume=" "
# Limit ad tracking
defaults write com.apple.AdLib forceLimitAdTracking -int 1
# Unsure whether this is the correct method of setting an IDFA
defaults write com.apple.AdLib AD_DEVICE_IDFA -string "00000000-0000-0000-0000-000000000000"
# Increase window resize speed for Cocoa applications
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001
# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Expand print panel by default
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Disable the "Are you sure you want to open this application?" dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false
# Remove duplicates in the "Open With" menu (also see `lscleanup` alias)
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
# Save to disk rather than iCloud by default
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Reveal IP address, hostname, OS version, etc. when clicking the clock in the login window
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
# Disable smart dashes as they're annoying when typing code
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Disable automatic period substitution as it's annoying when typing code
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false
# Disable smart quotes and smart dashes
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# Check for software updates daily rather than weekly
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
################################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
################################################################################
# Trackpad: enable tap to click for this user and for the login screen
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
# Increase sound quality for Bluetooth headphones/headsets
#defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
# Enable full keyboard access for all controls
# (e.g., enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Stop Apple Music from responding to the keyboard media keys
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2> /dev/null
################################################################################
# Screen #
################################################################################
# Require password immediately after sleep or screen saver begins
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
# Set screenshot format to PNG
defaults write com.apple.screencapture type -string "png"
# Save screenshots to downloads
defaults write com.apple.screencapture location -string "${HOME}/Downloads"
# Enable subpixel font rendering on non-Apple LCDs
defaults write NSGlobalDomain AppleFontSmoothing -int 2
################################################################################
# Finder #
################################################################################
# Disable Desktop icons
defaults write com.apple.finder CreateDesktop -bool false
# Show all filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# When performing a search, search the current folder by default
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Open new window to home directory
# Unsure whether this is enough or 'NewWindowTargetPath' also has to be set
defaults write com.apple.finder NewWindowTarget -string "PfHm"
# Open in window rather than tab
defaults write com.apple.finder FinderSpawnTab -bool false
# Avoid creating .DS_Store files on network or USB volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Automatically open a new Finder window when a volume is mounted
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
# Use column view in all Finder windows by default
# Four-letter codes for the other view modes: `icnv`, `Nlsv`, `Flwv`
defaults write com.apple.finder FXPreferredViewStyle -string "clmv"
# Enable AirDrop over Ethernet and on unsupported Macs running Lion
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
# Show the ~/Library folder
sudo chflags nohidden ~/Library
# Show the /Volumes folder
sudo chflags nohidden /Volumes
# 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
################################################################################
# Dock, Dashboard, and hot corners #
################################################################################
# Automatically hide and show the Dock
defaults write com.apple.dock autohide -bool true
# Set the icon size of Dock items to 72 pixels
defaults write com.apple.dock tilesize -int 72
# Disable recent dock items
defaults write com.apple.dock show-recents -bool false
################################################################################
# Safari & WebKit #
################################################################################
# Privacy: don't send search queries to Apple
defaults write com.apple.Safari UniversalSearchEnabled -bool false
defaults write com.apple.Safari SuppressSearchSuggestions -bool true
# Restore previous session
defaults write com.apple.Safari AlwaysRestoreSessionAtLaunch -bool true
# Prevent Safari from opening 'safe' files automatically after downloading
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
# Show status bar (i.e., hover over links to show URL)
defaults write com.apple.Safari ShowOverlayStatusBar -bool true
# Make Safari's search banners default to Contains instead of Starts With
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
# Enable the Develop menu and the Web Inspector in Safari
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
# Add a context menu item for showing the Web Inspector in web views
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
# Enable continuous spellchecking
defaults write com.apple.Safari WebContinuousSpellCheckingEnabled -bool true
# Disable auto-correct
defaults write com.apple.Safari WebAutomaticSpellingCorrectionEnabled -bool false
# Disable AutoFill
defaults write com.apple.Safari AutoFillFromAddressBook -bool false
defaults write com.apple.Safari AutoFillPasswords -bool false
defaults write com.apple.Safari AutoFillCreditCardData -bool false
defaults write com.apple.Safari AutoFillMiscellaneousForms -bool false
# Warn about fraudulent websites
defaults write com.apple.Safari WarnAboutFraudulentWebsites -bool true
# Enable debug menu and developer menu
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
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
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
# Make search banners default to Contains instead of Starts With
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
# Update extensions automatically
defaults write com.apple.Safari InstallExtensionUpdatesAutomatically -bool true
################################################################################
# Terminal #
################################################################################
# Only use UTF-8 in Terminal.app
defaults write com.apple.terminal StringEncodings -array 4
# Enable Secure Keyboard Entry in Terminal.app
# See: https://security.stackexchange.com/a/47786/8918
defaults write com.apple.terminal SecureKeyboardEntry -bool true
################################################################################
# Time Machine #
################################################################################
# Prevent Time Machine from prompting to use new hard drives as backup volume
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
################################################################################
# Activity Monitor #
################################################################################
# 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
################################################################################
# TextEdit, and Disk Utility #
################################################################################
# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
# Open and save files as UTF-8 in TextEdit
defaults write com.apple.TextEdit PlainTextEncoding -int 4
defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
################################################################################
# Mac App Store #
################################################################################
# Enable the WebKit Developer Tools in the Mac App Store
defaults write com.apple.appstore WebKitDeveloperExtras -bool true
# Enable Debug Menu in the Mac App Store
defaults write com.apple.appstore ShowDebugMenu -bool true
# Enable the automatic update check
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
# Download newly available updates in background
defaults write com.apple.SoftwareUpdate AutomaticDownload -int 1
# Install System data files & security updates
defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 1
# Turn on app auto-update
defaults write com.apple.commerce AutoUpdate -bool true
################################################################################
# Photos #
################################################################################
# Prevent Photos from opening automatically when devices are plugged in
defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
################################################################################
# Messages #
################################################################################
## Disable smart quotes as it's annoying for messages that contain code
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticQuoteSubstitutionEnabled" -bool false
################################################################################
# Mail #
################################################################################
# Setting email addresses to copy as '[email protected]' instead of 'Foo Bar <[email protected]>'
defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false
################################################################################
# Google Chrome & Google Chrome Canary #
################################################################################
## Expand the print dialog by default
defaults write com.google.Chrome PMPrintingExpandedStateForPrint2 -bool true
defaults write com.google.Chrome.canary PMPrintingExpandedStateForPrint2 -bool true
################################################################################
# Quicklook #
################################################################################
# Enable text selection
defaults write com.apple.finder QLEnableTextSelection -bool true
killall Finder
killall Dock
echo ""
echo "Done"
echo ""
echo "Optionally take the following steps:"
echo " - Set ZSH as the default shell"
echo " $ chsh -s /usr/local/bin/zsh"
echo " - Set a Terminal theme"
echo " - Restore settings from mackup"
echo " $ mackup restore"
echo " - Disable Photos iCloud sync"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment