Skip to content

Instantly share code, notes, and snippets.

@danieldraper
Created July 16, 2017 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldraper/c18eb3b0e5bc75b0b018b24fadebe612 to your computer and use it in GitHub Desktop.
Save danieldraper/c18eb3b0e5bc75b0b018b24fadebe612 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Author: Daniel Draper
# Credit:
# - https://github.com/vdka/dotfiles/
# - https://github.com/mathiasbynens/dotfiles
# Ask for the administrators password.
sudo -v
# Keep-alive: Update `sudo` timestamp until this file has finished executing.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Install available recommended updates.
echo "Updating OSX... (if restart required, re-run script)"
sudo softwareupdate --install --recommended --verbose
# Install Xcode command line tools.
echo "Installing Xcode command line tools..."
xcode-select --install
# ########################################################################### #
# General / UI #
# ########################################################################### #
# Set highlight color to green.
defaults write NSGlobalDomain AppleHighlightColor -string "0.764700 0.976500 0.568600"
# Set sidebar icon size to medium.
defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 2
# Expand the save panel by default.
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Disable smart quotes as they’re annoying when typing code.
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Automatically quit printer app once the print jobs complete.
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Expand print panel by default.
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# 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
# Restart automatically if the computer freezes.
sudo systemsetup -setrestartfreeze on
# ########################################################################### #
# 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 for all controls. (e.g. Enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Disable press-and-hold for keys in favor of key repeat.
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# The normal minimum is 15 (225 ms)
defaults write -g InitialKeyRepeat -int 12
# The normal minimum is 2 (30 ms)
defaults write -g KeyRepeat -int 1
# Set language and text formats.
# Note: if you’re in the US, replace `EUR` with `USD`, `Centimeters` with
# `Inches`, `en_GB` with `en_US`, and `true` with `false`.
defaults write NSGlobalDomain AppleLanguages -array "en" "nl"
defaults write NSGlobalDomain AppleLocale -string "en_US@currency=AUS"
defaults write NSGlobalDomain AppleMeasurementUnits -string "Centimeters"
defaults write NSGlobalDomain AppleMetricUnits -bool true
# ########################################################################### #
# 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
# Save screenshots in PNG format. (other options: BMP, GIF, JPG, PDF, TIFF)
defaults write com.apple.screencapture type -string "png"
# Change the default location for screenshots so they don't clutter desktop.
defaults write com.apple.screencapture location -string "${HOME}/Pictures/Screenshots"
# Enable subpixel font rendering on non-Apple LCDs.
# Reference: https://github.com/kevinSuttle/macOS-Defaults/issues/17#issuecomment-266633501
defaults write NSGlobalDomain AppleFontSmoothing -int 2
# Enable HiDPI display modes (requires restart).
sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
# ########################################################################### #
# Finder #
# ########################################################################### #
# Set Desktop as the default location for new Finder windows.
# For other paths, use `PfLo` and `file:///full/path/here/`
defaults write com.apple.finder NewWindowTarget -string "PfDe"
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/Desktop/"
# 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
# Show all filename extensions.
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Show status bar.
defaults write com.apple.finder ShowStatusBar -bool true
# Show path bar.
defaults write com.apple.finder ShowPathbar -bool true
# Keep folders on top when sorting by name.
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# Allow text selection in Quick Look.
defaults write com.apple.finder QLEnableTextSelection -bool true
# When performing a search, search the current folder by default.
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Disable the warning when changing a file extension.
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Enable spring loading for directories.
defaults write NSGlobalDomain com.apple.springing.enabled -bool true
# Tweak the spring loading delay for directories.
defaults write NSGlobalDomain com.apple.springing.delay -float .5
# Avoid creating .DS_Store files on network volumes.
defaults write com.apple.desktopservices DSDontWriteNetworkStores -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
# 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
# Use list view in all Finder windows by default.
# The four-letter codes for the different view modes: `icnv`, `clmv`, `Flwv`
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Enable AirDrop over Ethernet and on unsupported Macs running Lion.
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -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
# ########################################################################### #
# Dock #
# ########################################################################### #
# Show indicator lights for open applications in the Dock.
defaults write com.apple.dock show-process-indicators -bool true
# Don’t automatically rearrange Spaces based on most recent use.
defaults write com.apple.dock mru-spaces -bool false
# Set the icon size of Dock items to 28 pixels.
defaults write com.apple.dock tilesize -int 28
# Minimize windows into their application’s icon.
defaults write com.apple.dock minimize-to-application -bool true
# Automatically hide and show the Dock.
defaults write com.apple.dock autohide -bool true
# Disable the Launchpad gesture (pinch with thumb and three fingers).
defaults write com.apple.dock showLaunchpadGestureEnabled -int 0
# ########################################################################### #
# Safari & WebKit #
# ########################################################################### #
# Enable Safari’s debug menu.
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
# 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
# Prevent safari from opening safe files automatically after downloading.
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
# Enable “Do Not Track”.
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true
# ########################################################################### #
# Terminal & iTerm 2 #
# ########################################################################### #
# Only use UTF-8 in Terminal.app.
defaults write com.apple.terminal StringEncodings -array 4
# Don’t display the annoying prompt when quitting iTerm.
defaults write com.googlecode.iterm2 PromptOnQuit -bool false
# ########################################################################### #
# 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
# ########################################################################### #
# Mac App Store #
# ########################################################################### #
# Enable the automatic update check.
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
# Check for software updates daily, not just once per week.
defaults write com.apple.SoftwareUpdate ScheduleFrequency -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
# ########################################################################### #
# Photos #
# ########################################################################### #
# Prevent Photos from opening automatically when devices are plugged in.
defaults -currentHost write com.apple.ImageCapture disableHotPlug -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
# Disable local Time Machine backups.
hash tmutil &> /dev/null && sudo tmutil disablelocal
# ########################################################################### #
# 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
# ########################################################################### #
# Google Chrome & Google Chrome Canary #
# ########################################################################### #
# Allow installing user scripts via GitHub Gist or Userscripts.org.
defaults write com.google.Chrome ExtensionInstallSources -array "https://gist.githubusercontent.com/" "http://userscripts.org/*"
defaults write com.google.Chrome.canary ExtensionInstallSources -array "https://gist.githubusercontent.com/" "http://userscripts.org/*"
# Use the system-native print preview dialog.
defaults write com.google.Chrome DisablePrintPreview -bool true
defaults write com.google.Chrome.canary DisablePrintPreview -bool true
# Expand the print dialog by default.
defaults write com.google.Chrome PMPrintingExpandedStateForPrint2 -bool true
defaults write com.google.Chrome.canary PMPrintingExpandedStateForPrint2 -bool true
# ########################################################################### #
# Kill affected applications #
# ########################################################################### #
for app in "Activity Monitor" \
"cfprefsd" \
"Dock" \
"Finder" \
"Google Chrome Canary" \
"Google Chrome" \
"Messages" \
"Photos" \
"Safari" \
"SystemUIServer" \
"Terminal"; do
killall "${app}" > /dev/null 2>&1
done
echo "Done. It's recommend you restart to ensure all changes are applied."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment