Lhadalo
8/19/2019 - 11:10 AM

Script for setting up macOS as an Android developer

Script for setting up macOS as an Android developer

#!/usr/bin/env bash
# 
# Bootstrap script for setting up a new OSX machine
# 
# This should be idempotent so it can be run multiple times.
#
# Some apps don't have a cask and so still need to be installed by hand. These
# include:
#
# - Twitter (app store)
# - Postgres.app (http://postgresapp.com/)
#
# Notes:
#
# - If installing full Xcode, it's better to install that first from the app
#   store before running the bootstrap script. Otherwise, Homebrew can't access
#   the Xcode libraries as the agreement hasn't been accepted yet.
#
# Original script: https://gist.github.com/codeinthehole/26b37efa67041e1307db
# Original preferences: https://github.com/mathiasbynens/dotfiles/blob/master/.macos
#

#Check if homebrew is installed
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 doctor
brew update

# If Flutter should be installed
brew tap MiderWong/flutter

# If react native/flutter should be installed. Add wanted packages
PACKAGES=(
    node #For react native
    npm #For react native
    watchman #For react native
    flutter #For Flutter
)

echo "Installing packages..."
brew install ${PACKAGES[@]}

echo "Cleaning up..."
brew cleanup

echo "Installing cask..."
brew install caskroom/cask/brew-cask


brew tap AdoptOpenJDK/openjdk #If React Native should be installed

#Most usual applications here. Add more that are wanted.
CASKS=(
    fastlane
    adoptopenjdk8 #For react native
    reactotron #For react native
    visual-studio-code
    intellij-idea-ce
    android-studio
    google-chrome
    slack
    iterm2
)

brew cask install ${CASKS[@]}

echo "Installing Ruby gems"
RUBY_GEMS=(
    bundler
    filewatcher
    timetrap #timetrap: https://github.com/samg/timetrap
)
sudo gem install ${RUBY_GEMS[@]}

echo "Install React Native"
npm install -g react-native-cli

#Preferences for OSX. Remove/Add as wanted
echo "Configuring OSX..."

# 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

# Hot corners: Put display to sleep (Bottom-Right)
defaults write com.apple.dock wvous-br-corner -int 5
defaults write com.apple.dock wvous-br-modifier -int 0

# Configure Dock
defaults write com.apple.dock mineffect -string scale #Scale effect for minimize
defaults write com.apple.dock no-bouncing -bool TRUE #No bouncing when app want attention
defaults write com.apple.dock launchanim -bool false; #Disable launch animation for Dock
defaults write com.apple.dock show-recents -bool false #Remove Recents section in Dock
defaults write com.apple.dock tilesize -int 39; #Set size to 39
defaults write com.apple.dock autohide -bool true #Enable autohide
defaults write com.apple.dock autohide-time-modifier -float 0.7  #Faster animation time for autohide
defaults write com.apple.Dock autohide-delay -float 0 #Remove delay for Dock to be shown

# 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

# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false

# Disable press-and-hold for keys in favor of key repeat
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

# Disable automatic capitalization as it’s annoying when typing code
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false

# Disable smart quotes as they’re annoying when typing code
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false

# Use list view in all Finder windows by default
# Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv`
defaults write com.apple.finder FXPreferredViewStyle -string 'clmv'

# Keep folders on top when sorting by name
defaults write com.apple.finder _FXSortFoldersFirst -bool true

# When performing a search, search the current folder by default
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"

# 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

# Don’t display the annoying prompt when quitting iTerm
defaults write com.googlecode.iterm2 PromptOnQuit -bool false

echo "Creating folder structure..."
[[ ! -d Code ]] && mkdir Code #Create Code directory where the script is run. 

# Restart affected applications
for app in "Activity Monitor" \
"cfprefsd" \
"Dock" \
"Finder" \
"SystemUIServer"; do
killall "${app}" &> /dev/null
done