Skip to content

Instantly share code, notes, and snippets.

@fergus
Created March 5, 2015 02:34
Show Gist options
  • Save fergus/83f5f28e68a885d37dd0 to your computer and use it in GitHub Desktop.
Save fergus/83f5f28e68a885d37dd0 to your computer and use it in GitHub Desktop.
osx initiation script
#!/bin/sh
# This is the initiation script I use for my mac.
# I have pilfered and pinched from lots of places on the web.
# http://lapwinglabs.com/blog/hacker-guide-to-setting-up-your-mac
# https://gist.github.com/brandonb927/3195465
# https://github.com/mathiasbynens/dotfiles
# https://github.com/diimdeep/dotfiles/blob/master/osx/configure/yosemite/osx_set_defaults.sh
# http://twnsnd.co/beta-site/journal/fresh-install-yosemite/
# Ultimatly this script has been designed for me and the way I like to operate.
# Use as you see fit.
# Set the colours you can use
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
# Bold
bold=`tput bold`
# Resets the style
normal=`tput sgr0`
# arg $1 = message
# arg $2 = Color
cecho() {
echo "${2}${bold}${1}${normal}"
return
}
# Set continue to false by default
CONTINUE=false
echo ""
cecho "###############################################" $red
cecho "# DO NOT RUN THIS SCRIPT BLINDLY #" $red
cecho "# YOU'LL PROBABLY REGRET IT... #" $red
cecho "# #" $red
cecho "# READ IT THOROUGHLY #" $red
cecho "# AND EDIT TO SUIT YOUR NEEDS #" $red
cecho "###############################################" $red
echo ""
echo ""
cecho "Have you read through the script you're about to run and " $red
cecho "understood that it will make changes to your computer? (y/n)" $red
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
CONTINUE=true
fi
if ! $CONTINUE; then
# Check if we're continuing and output a message if not
cecho "Please go read the script, it only takes a few minutes" $red
exit
fi
# Here we go.. ask for the administrator password upfront and run a
# keep-alive to update existing `sudo` time stamp until script has finished
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Build locate database (/var/db/locate.database)
cecho "Building the locate database..." $white
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
###############################################################################
# Install Homebrew
###############################################################################
# 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
cecho "Update homebrew recipes.." $green
brew update
brew upgrade
###############################################################################
# Install Updates to standard UNIX tools
###############################################################################
# Install GNU core utilities (those that come with OS X are outdated)
brew install coreutils
sudo ln -s /usr/local/bin/gsha256sum /usr/local/bin/sha256sum
#########################
# TODO
# Update the path for ~/.bash_profile or ~/.path
# Add the path temp now
$PATH=$(brew --prefix coreutils)/libexec/gnubin:$PATH
# Install some other useful utilities like `sponge`.
brew install moreutils
# Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
brew install findutils
# Install GNU `sed`, overwriting the built-in `sed`.
brew install gnu-sed --with-default-names
# Install Bash 4.
#########################
# TODO
# Note: don’t forget to add `/usr/local/bin/bash` to `/etc/shells` before running `chsh`.
# list the shells file for now
cat /etc/shells
brew install bash
brew install bash-completion
# Install more recent versions of some OS X tools
brew tap homebrew/dupes
brew install homebrew/dupes/grep
brew install homebrew/dupes/openssh
brew install homebrew/dupes/screen
brew install homebrew/php/php55 --with-gmp
###############################################################################
# Install standard tools
###############################################################################
brew install node
brew install io
brew install cmake
brew install git
brew install htop-osx
brew install iftop
brew install tmux
brew install tmux-mem-cpu-load
brew install ffmpeg
brew install python
brew install wget --with-iri # Install `wget` with IRI support.
brew install imagemagick --with-webp
brew install lynx
brew install tree
brew install mtr --no-gtk
brew cleanup
###############################################################################
# Install apps with Homebrew Cask
###############################################################################
#Full list of app https://github.com/caskroom/homebrew-cask/tree/master/Casks
#install Homebrew Cask
brew install caskroom/cask/brew-cask
apps=(
alfred
vlc
google-chrome
firefox
spotify
spotify-menubar
spotify-notifications
iterm2
sublime-text3
skype
transmission
adobe-photoshop-lightroom
steam
#lastpass
lastpass-universal
vmware-fusion
xquartz
#flux
qlcolorcode
qlmarkdown
qlprettypatch
qlstephen
quicklook-json
quicklook-csv
betterzipql
qlimagesize
webpquicklook
appcleaner
#flash
flash-player
processing
arduino
guthub
java
the-unarchiver
carbon-copy-cloner
torbrowser
google-earth
#oneNote
#onedriveforbusiness
)
# Install apps to /Applications
# Default is: /Users/$user/Applications
cecho "Installing apps..." $green
brew cask install --appdir="/Applications" ${apps[@]}
#Add /opt/homebrew-cask/Caskroom/. path to Alfred
brew cask alfred link
cecho "Resetting Quick Look..." $green
#resets Quick Look Server and all Quick Look client's generator cache
qlmanage -r
###############################################################################
# Install Fonts with Homebrew Cask
###############################################################################
# Full list of fonts https://github.com/caskroom/homebrew-fonts/tree/master/Casks
fonts=(
font-m-plus
font-clear-sans
font-roboto
font-verdana
font-ubuntu
font-droid-sans
font-droid-sans-mono
font-droid-serif.rb
)
# install fonts
cecho "Installing fonts..." $green
brew cask install ${fonts[@]}
###############################################################################
# General UI/UX
###############################################################################
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 "Expanding the save panel by default"
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
echo ""
echo "Automatically quit printer app once the print jobs complete"
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
echo ""
echo "Displaying ASCII control characters using caret notation in standard text views"
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
echo ""
echo "Save to disk, rather than iCloud, by default"
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
echo ""
echo "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
echo ""
echo "Show shutdown buttons in the login window"
sudo defaults write /Library/Preferences/com.apple.loginwindow PowerOffDisabled -bool false
echo ""
echo "Check for software updates daily, not just once per week"
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
echo ""
echo "Allow fast user switching"
sudo defaults write /Library/Preferences/.GlobalPreferences MultipleSessionEnabled -bool true
echo ""
echo "Removing duplicates in the 'Open With' menu"
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
echo ""
echo "Set Help Viewer windows to non-floating mode"
defaults write com.apple.helpviewer DevMode -bool true
echo ""
echo "Restart automatically if the computer freezes"
systemsetup -setrestartfreeze on
echo ""
echo "Disable sound effects on boot"
sudo nvram SystemAudioVolume=" "
echo ""
echo "Enable AirDrop over Ethernet and on unsupported Macs running Lion"
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
echo ""
echo "Enable the SuperDrive on any Mac"
sudo nvram boot-args="mbasd=1"
###############################################################################
# General Power and Performance modifications
###############################################################################
echo ""
echo "Disable the sudden motion sensor? (it's not useful for SSDs/current MacBooks)"
sudo pmset -a sms 0
echo ""
echo "Disable system-wide resume"
defaults write com.apple.systempreferences NSQuitAlwaysKeepsWindows -bool false
echo ""
echo "Disable the menubar transparency"
defaults write com.apple.universalaccess reduceTransparency -bool true
################################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input
################################################################################
echo ""
echo "Increasing sound quality for Bluetooth headphones/headsets"
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
echo ""
echo "Enabling full keyboard access for all controls (enable Tab in modal dialogs, menu windows, etc.)"
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
echo ""
echo "Setting trackpad & mouse speed to a reasonable number"
defaults write -g com.apple.trackpad.scaling 2
defaults write -g com.apple.mouse.scaling 2.5
echo "Trackpad: map bottom right corner to right-click"
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true
defaults -currentHost write NSGlobalDomain com.apple.trackpad.trackpadCornerClickBehavior -int 1
defaults -currentHost write NSGlobalDomain com.apple.trackpad.enableSecondaryClick -bool true
echo ""
echo "Use scroll gesture with the Ctrl (^) modifier key to zoom"
defaults write com.apple.universalaccess closeViewScrollWheelToggle -bool true
defaults write com.apple.universalaccess HIDScrollZoomModifierMask -int 262144
echo "Follow the keyboard focus while zoomed in"
defaults write com.apple.universalaccess closeViewZoomFollowsFocus -bool true
#echo ""
#echo "Turn off keyboard illumination when computer is not used for 5 minutes"
#defaults write com.apple.BezelServices kDimTime -int 300
###############################################################################
# Screen
###############################################################################
echo ""
echo "Enabling subpixel font rendering on non-Apple LCDs"
defaults write NSGlobalDomain AppleFontSmoothing -int 2
echo ""
echo "Enabling HiDPI display modes (requires restart)"
sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
###############################################################################
# Finder
###############################################################################
echo ""
echo "Set sidebar icon size to medium"
defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 2
echo ""
echo "Set default location for new Finder windows. For other paths, use `PfLo` and `file:///full/path/here/`"
defaults write com.apple.finder NewWindowTarget -string "PfLo"
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/"
echo ""
echo "Show hidden files in Finder by default"
defaults write com.apple.Finder AppleShowAllFiles -bool true
echo ""
echo "Show all filename extensions in Finder by default"
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
echo ""
echo "Show status bar in Finder by default"
defaults write com.apple.finder ShowStatusBar -bool true
echo ""
echo "Avoid creation of .DS_Store files on network volumes"
defaults write com.apple.desktopservices DSDontWriteNetworkStores -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 "Setting the icon size of Dock items to 36 pixels for optimal size/screen-realestate"
defaults write com.apple.dock tilesize -int 36
echo ""
echo "Speeding up Mission Control animations and grouping windows by application"
defaults write com.apple.dock expose-animation-duration -float 0.14
defaults write com.apple.dock "expose-group-by-app" -bool true
echo ""
echo "When performing a search, search the current folder by default"
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
echo ""
echo "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
echo ""
echo "Use list view in all Finder windows by default"
cecho "Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv`,`Nlsv`" $green
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
echo ""
echo "Show the ~/Library folder"
chflags nohidden ~/Library
###############################################################################
# Chrome, Safari, & WebKit
###############################################################################
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 "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
###############################################################################
# Mail
###############################################################################
echo ""
echo "Setting email addresses to copy as 'foo@example.com' instead of 'Foo Bar <foo@example.com>' in Mail.app"
defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false
###############################################################################
# TextEdit
###############################################################################
echo ""
echo "Use plain text mode for new documents"
defaults write com.apple.TextEdit RichText -int 0
echo "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
###############################################################################
# Terminal
###############################################################################
echo ""
echo "Enabling UTF-8 ONLY in Terminal.app and setting the Pro theme by default"
defaults write com.apple.terminal StringEncodings -array 4
defaults write com.apple.Terminal "Default Window Settings" -string "Pro"
defaults write com.apple.Terminal "Startup Window Settings" -string "Pro"
echo "New tabs open with Default Working Directory"
defaults write com.apple.Terminal NewTabWorkingDirectoryBehavior -bool true
###############################################################################
# iTerm 2
###############################################################################
echo ""
echo "Don’t display the annoying prompt when quitting iTerm"
defaults write com.googlecode.iterm2 PromptOnQuit -bool false
###############################################################################
# Activity Monitor
###############################################################################
echo ""
echo "Show the main window when launching Activity Monitor"
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
echo "Visualize CPU usage in the Activity Monitor Dock icon"
defaults write com.apple.ActivityMonitor IconType -int 5
echo "Show all processes in Activity Monitor"
defaults write com.apple.ActivityMonitor ShowCategory -int 0
echo "Sort Activity Monitor results by CPU usage"
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage"
defaults write com.apple.ActivityMonitor SortDirection -int 0
###############################################################################
# Transmission.app
###############################################################################
echo ""
cecho "Transmission" $green
echo "Setting up an incomplete downloads folder in Downloads"
mkdir -p ~/Downloads/Incomplete
defaults write org.m0k.transmission UseIncompleteDownloadFolder -bool true
defaults write org.m0k.transmission IncompleteDownloadFolder -string "${HOME}/Downloads/Incomplete"
echo "Don't prompt for confirmation before downloading"
defaults write org.m0k.transmission DownloadAsk -bool false
echo "Trash original torrent files"
defaults write org.m0k.transmission DeleteOriginalTorrent -bool true
echo "Hide the donate message"
defaults write org.m0k.transmission WarningDonate -bool false
echo "Hide the legal disclaimer"
defaults write org.m0k.transmission WarningLegal -bool false
###############################################################################
# Sublime Text
###############################################################################
echo "Setting Git to use Sublime Text as default editor"
git config --global core.editor "subl -n -w"
echo "Install Sublime Text 3 Package Control
wget https://sublime.wbond.net/Package%20Control.sublime-package
mv Package\ Control.sublime-package ~/Library/Application\ Support/Sublime\ Text\ 3/Installed\ Packages/
echo ""
cecho "Done!" $cyan
echo ""
echo ""
cecho "################################################################################" $white
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment