Skip to content

Instantly share code, notes, and snippets.

@xcdx80
Created June 27, 2017 14:44
Show Gist options
  • Save xcdx80/2cca1d0c843f14114de03f56722fad20 to your computer and use it in GitHub Desktop.
Save xcdx80/2cca1d0c843f14114de03f56722fad20 to your computer and use it in GitHub Desktop.
echo "Starting bootstrapping"
# Request admin password and run a keep-alvie
# to keep using sudo until the script has finished
echo " We need administrator privileges for the execution of this script..."
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# ==============================================
# Apps
# ==============================================
# Check for Homebrew, install if we don't have it
if test ! $(which brew); then
echo "Installing homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Update homebrew recipes
brew update
# Install Bash 4
brew install bash
# Install Mac App Store CLI (https://github.com/mas-cli/mas)
brew install mas
PACKAGES=(
node@6
maven
wget
reveal
surfeasy-vpn
charles
iterm2
fantastical
hockey
1password
sizeup
)
echo "Installing packages..."
brew install ${PACKAGES[@]}
echo "Cleaning up..."
brew cleanup
echo "Installing cask..."
brew install caskroom/cask/brew-cask
CASKS=(
alfred
dashlane
docker
dropbox
evernote
flux
franz
gotomeeting
google-chrome
hipchat
microsoft-office
skype
spotify
sublime-text2
virtualbox
zsh
git
atom
dash
duet
sourcetree
)
echo "Installing cask apps..."
brew cask install ${CASKS[@]}
# ==============================================
# Fonts
# ==============================================
echo "Installing fonts..."
brew tap caskroom/fonts
FONTS=(
font-roboto
)
brew cask install ${FONTS[@]}
echo "Installing global npm packages..."
npm install marked -g
# ==============================================
# macOS Configuration
# ==============================================
echo ""
echo "Configuring macOS..."
echo ""
echo "Would you like to set your computer name (as done via System Preferences → Sharing)? (y/n)"
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "What would you like it to be?"
read COMPUTER_NAME
sudo scutil --set ComputerName $COMPUTER_NAME
sudo scutil --set HostName $COMPUTER_NAME
sudo scutil --set LocalHostName $COMPUTER_NAME
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $COMPUTER_NAME
fi
echo ""
echo "Automatically quit printer app once the print jobs complete"
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
echo ""
echo "Expand save panel by default"
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
echo ""
echo "Expand print panel by default"
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# ==============================================
# Files and folders
# ==============================================
# Show the ~/Library directory
#chflags nohidden "${HOME}/Library"
# Don't show the ~/bin directory
#chflags hidden "${HOME}/bin"
echo ""
echo "Show filename extensions by default"
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# ==============================================
# Finder
# ==============================================
echo ""
echo "New window points to home"
defaults write com.apple.finder NewWindowTarget -string "PfHm"
echo ""
echo "When performing a search, search the current folder by default"
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
echo ""
echo "Avoid creating .DS_Store files on network volumes"
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
echo ""
echo "Show path in Finder title bar"
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
echo ""
echo "Show status bar in Finder"
defaults write com.apple.finder ShowStatusBar -bool true
echo ""
echo "Allowing text selection in Quick Look/Preview in Finder by default"
defaults write com.apple.finder QLEnableTextSelection -bool true
echo ""
echo "Use column view in all Finder windows by default? (y/n)"
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
defaults write com.apple.finder FXPreferredViewStyle Clmv
fi
echo ""
echo "Show hidden files in Finder by default? (y/n)"
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
defaults write com.apple.Finder AppleShowAllFiles -bool true
fi
echo ""
echo "Disable the warning when changing a file extension? (y/n)"
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
fi
# ==============================================
# Dock & Status Bar
# ==============================================
echo ""
echo "Setting Dock preferences"
echo ""
echo "Automatically hide and show the Dock"
defaults write com.apple.dock autohide -bool true
echo ""
echo "Set up Dock icon sizes"
defaults write com.apple.dock tilesize -float 44
defaults write com.apple.dock largesize -float 64
echo ""
echo "Automatically hide and show the status bar"
defaults write NSGlobalDomain _HIHideMenuBar -bool true
# ==============================================
# Locale
# ==============================================
echo ""
echo "Set locale to en_NL"
defaults write NSGlobalDomain AppleLocale -string "en_NL"
defaults write NSGlobalDomain AppleMeasurementUnits -string "Centimeters"
defaults write NSGlobalDomain AppleMetricUnits -bool true
# 24-Hour Time // AppleICUForce12HourTime doesnt exist on 10.12.5
#echo "Enable 24-Hour time"
#defaults write NSGlobalDomain AppleICUForce12HourTime -bool false
# ==============================================
# Text
# ==============================================
echo ""
echo "Disable auto-correct"
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# ==============================================
# Desktop & Screensaver
# ==============================================
echo ""
echo "Set MacOS theme to Dark Mode"
sudo defaults write /Library/Preferences/.GlobalPreferences AppleInterfaceTheme Dark
echo ""
echo "Require password as soon as screensaver or sleep mode starts"
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
echo ""
echo "Enable snap-to-grid for icons on the desktop and in other icon views"
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
echo ""
echo "Set up 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
# Top left screen corner → Mission Control
#defaults write com.apple.dock wvous-tl-corner -int 2
#defaults write com.apple.dock wvous-tl-modifier -int 0
echo ""
echo "> Top right screen corner → Desktop"
defaults write com.apple.dock wvous-tr-corner -int 4
defaults write com.apple.dock wvous-tr-modifier -int 0
#echo "Bottom right screen corner → Start screen saver"
#defaults write com.apple.dock wvous-br-corner -int 5
#defaults write com.apple.dock wvous-br-modifier -int 0
echo ""
echo "> Bottom left screen corner → Sleep"
defaults write com.apple.dock wvous-bl-corner -int 10
defaults write com.apple.dock wvous-bl-modifier -int 0
echo ""
echo "Where do you want screenshots to be stored? (hit ENTER if you want ~/Desktop as default)"
# Thanks https://github.com/omgmog
read screenshot_location
echo ""
if [ -z "${screenshot_location}" ]
then
# If nothing specified, we default to ~/Desktop
screenshot_location="${HOME}/Desktop"
else
# Otherwise we use input
if [[ "${screenshot_location:0:1}" != "/" ]]
then
# If input doesn't start with /, assume it's relative to home
screenshot_location="${HOME}/${screenshot_location}"
fi
fi
echo "Setting location to ${screenshot_location}"
defaults write com.apple.screencapture location -string "${screenshot_location}"
echo ""
echo "What format should screenshots be saved as? (hit ENTER for PNG, options: BMP, GIF, JPG, PDF, TIFF) "
read screenshot_format
if [ -z "$1" ]
then
echo ""
echo "Setting screenshot format to PNG"
defaults write com.apple.screencapture type -string "png"
else
echo ""
echo "Setting screenshot format to $screenshot_format"
defaults write com.apple.screencapture type -string "$screenshot_format"
fi
# ==============================================
# Mouse & Trackpad
# ==============================================
echo ""
echo "Increase mouse sensitivity"
defaults write -g com.apple.mouse.scaling 3
echo ""
echo "Tap with two fingers to emulate right click"
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true
echo ""
echo "Enable three finger tap (look up)"
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerTapGesture -int 2
echo ""
echo "Enable pinch to zoom in or out"
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadPinch -bool true
echo ""
echo "Enable tap-to-click"
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
echo ""
echo "Enable \"tap-and-a-half\" to drag."
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Dragging -int 1
defaults write com.apple.AppleMultitouchTrackpad Dragging -int 1
echo ""
echo "Disable \"natural\" scroll"
defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
# ==============================================
# Photos
# ==============================================
echo ""
echo "Stop Photos from opening automatically when a new iPhone is plugged in"
defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
# ==============================================
# Keyboard
# ==============================================
echo ""
echo "Increase keyboard key repeat rate"
defaults write -g InitialKeyRepeat -int 10 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 1 # normal minimum is 2 (30 ms)
echo ""
echo "Enable full keyboard access for all controls"
# (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# ==============================================
# Bluetooth
# ==============================================
echo ""
echo "Increase sound quality for Bluetooth headphones/headsets"
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
# ==============================================
# Archive Utility
# ==============================================
echo ""
echo "Setting Archive Utility preferences"
# Move archives to trash after extraction
defaults write com.apple.archiveutility "dearchive-move-after" -string "~/.Trash"
# Don't reveal extracted items
defaults write com.apple.archiveutility "dearchive-reveal-after" -bool false
echo ""
echo "Privacy: Don't send search queries to Apple"
defaults write com.apple.Safari UniversalSearchEnabled -bool false
defaults write com.apple.Safari SuppressSearchSuggestions -bool true
echo ""
echo "Hiding Safari's bookmarks bar by default"
defaults write com.apple.Safari ShowFavoritesBar -bool false
echo ""
echo "Hiding Safari's sidebar in Top Sites"
defaults write com.apple.Safari ShowSidebarInTopSites -bool false
echo ""
echo "Disabling Safari's thumbnail cache for History and Top Sites"
defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2
echo ""
echo "Enabling Safari's debug menu"
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
echo ""
echo "Making Safari's search banners default to Contains instead of Starts With"
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
echo ""
echo "Removing useless icons from Safari's bookmarks bar"
defaults write com.apple.Safari ProxiesInBookmarksBar "()"
echo ""
echo "Enabling 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
echo ""
echo "Adding a context menu item for showing the Web Inspector in web views"
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
echo ""
echo "Disabling the annoying backswipe in Chrome"
defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false
defaults write com.google.Chrome.canary AppleEnableSwipeNavigateWithScrolls -bool false
echo ""
echo "Using the system-native print preview dialog in Chrome"
defaults write com.google.Chrome DisablePrintPreview -bool true
defaults write com.google.Chrome.canary DisablePrintPreview -bool true
echo "Bootstrapping complete"
# ==============================================
# Kill affected applications
# ==============================================
function killallApps() {
killall "Finder" > /dev/null 2>&1
killall "SystemUIServer" > /dev/null 2>&1
killall "Dock" > /dev/null 2>&1
appsToKill=(
"Dashboard"
"System Preferences"
"Xcode"
"Safari"
)
for app in "${appsToKill[@]}"
do
killall "${app}" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
# We just killed an app so restart it
open -a "${app}"
fi
done
echo "Note that some of these changes require a logout/restart to take effect."
}
printf "Restart the affected applications? (y/n): "
read killallReply
if [[ $killallReply =~ ^[Yy]$ ]]; then
killallApps
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment