Skip to content

Instantly share code, notes, and snippets.

@anth-3
Last active August 29, 2015 14:24
Show Gist options
  • Save anth-3/a2696e55ccc481a55832 to your computer and use it in GitHub Desktop.
Save anth-3/a2696e55ccc481a55832 to your computer and use it in GitHub Desktop.
#!/bin/sh
################################################################################
# OSX Hacks: Yosemite Edition #
# #
# This script is taken mainly from osx-for-hackers.sh by Brandon Brown, while #
# adding my own options, and not using those that I did not find necessary. #
# #
# Version: 2 July 2015 rev 2 #
# #
# References: #
# - https://gist.github.com/brandonb927/3195465 #
# - https://github.com/mathiasbynens/dotfiles/blob/master/.osx #
# #
# The MIT License (MIT) #
# Copyright (c) 2015 Anthony Holdener III #
################################################################################
# We want the script to have fancy colors, don't we?
black='\033[0;30m'
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
white='\033[0;37m'
# Reset the style of echo
reset=`tput sgr0`
no_r=true
# This function allows us to echo colors to the terminal and have the terminal
# automatically reset after echoing the line to the user, making it less of a
# burden on the scripter to echo colors to the user. Taken from @joaocunha and
# osx-for-hackers.sh by Brandon Brown.
#
# $1 - the color to make the echo
# $2 - the message to echo
# $3 - should the echo stay on the same line?
cecho() {
if [ "${3}" = true ]; then
echo "${1}${2}${reset} \c"
else
echo "${1}${2}${reset}"
fi
return
}
# This function allows us to echo the success or failure of a command instead of
# having multiple lines of command; check; for each command -- this keeps the
# script cleaner and many fewer lines.
#
# $1 - the command to execute
run_command() {
$1
if [ $? -eq 0 ]; then
cecho $green "Done."
else
cecho $red "Failed."
fi
return
}
# Set continue to false by default
CONTINUE=false
echo ""
cecho $red "############################################################"
cecho $red "# DO NOT RUN THIS SCRIPT UNLESS YOU HAVE READ #"
cecho $red "# THROUGH IT AND KINDA HAVE A CLUE AS TO #"
cecho $red "# WHAT YOU ARE DOING... #"
cecho $red "# #"
cecho $red "# MODIFY THE SCRIPT AS YOU SEE FIT #"
cecho $red "############################################################"
echo ""
echo ""
cecho $yellow "Have you read through the script you are about to run and"
cecho $yellow "understand that it will make changes to your computer? (y/N)" $no_r
read -r RESPONSE
if [[ $RESPONSE =~ ^([yY][eE][sS]|[yY])$ ]]; then
CONTINUE=true
fi
if ! $CONTINUE; then
echo ""
cecho $magenta "Please read through the script. It only takes a few minutes."
echo ""
exit 1
fi
# Now that the preliminaries are out of the way, get the root password and run a
# keep-alive to update the existing `sudo` timestamp until the script has
# finished executing
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
################################################################################
# General UI/UX Configurations #
################################################################################
echo ""
cecho $cyan "General UI/UX Configurations..."
echo ""
cecho $yellow "What is the name of this computer?" $no_r
read COMPUTER_NAME
echo "Changing 'ComputerName' to '$COMPUTER_NAME'...\c"
run_command `sudo scutil --set ComputerName $COMPUTER_NAME`
echo "Changing 'HostName' to '$COMPUTER_NAME'...\c"
run_command `sudo scutil --set HostName $COMPUTER_NAME`
echo "Changing 'LocalHostName' to '$COMPUTER_NAME'...\c"
run_command `sudo scutil --set LocalHostName $COMPUTER_NAME`
echo "Writing '$COMPUTER_NAME' to 'NetBIOSName' to /Library/Preferences/SystemConfiguration/com.apple.smb.server...\c"
run_command `sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $COMPUTER_NAME`
echo ""
echo "Checking for software updates daily, and not just once per week...\c"
run_command `sudo defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1`
echo "Removing duplicates in the 'Open With' menu...\c"
run_command `sudo /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user`
echo "Addinf ability to toggle between Light and Dark mode in Yosemite using ctrl+opt+cmd+t...\c"
# http://www.reddit.com/r/apple/comments/2jr6s2/1010_i_found_a_way_to_dynamically_switch_between/
run_command `sudo defaults write /Library/Preferences/.GlobalPreferences.plist _HIEnableThemeSwitchHotKey -bool true`
################################################################################
# General Power and Performance Modifications #
################################################################################
echo ""
cecho $cyan "General Power and Performance Modifications..."
echo ""
echo "Disabling hibernation (speeds up entering sleep mode)...\c"
run_command `sudo pmset -a hibernatemode 0`
echo "Disabling the sudden motion sensor (not useful for SSDs)...\c"
run_command `sudo pmset -a sms 0`
echo "Disabling the menubar transparency...\c"
run_command `sudo defaults write com.apple.universalaccess reduceTransparency -bool true`
echo "Speeding up wake from sleep to 24 hours from an hour...\c"
# http://www.cultofmac.com/221392/quick-hack-speeds-up-retina-macbooks-wake-from-sleep-os-x-tips/
run_command `sudo pmset -a standbydelay 86400`
################################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and Input Configurations #
################################################################################
echo ""
cecho $cyan "Trackpad, mouse, keyboard, Bluetooth accessories, and Input Configurations..."
echo ""
echo "Increasing sound quality for Bluetooth headphones/headsets...\c"
run_command `sudo defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40`
echo "Enabling full keyboard access for all controls (enable Tab in modal dialogs, menu windows, etc.)...\c"
run_command `sudo defaults write NSGlobalDomain AppleKeyboardUIMode -int 3`
echo "Setting a blazingly fast keyboard repeat rate...\c"
run_command `sudo defaults write NSGlobalDomain KeyRepeat -int 0`
echo "Setting trackpad speed to a reasonable number...\c"
run_command `sudo defaults write -g com.apple.trackpad.scaling 2`
echo "Setting mouse speed to a reasonable number...\c"
run_command `sudo defaults write -g com.apple.mouse.scaling 2.5`
echo "Turning off keyboard illumination when computer is not used for 5 minutes...\c"
run_command `sudo defaults write com.apple.BezelServices kDimTime -int 300`
echo "Disabling display from automatically adjusting brightness...\c"
run_command `sudo defaults write /Library/Preferences/com.apple.iokit.AmbientLightSensor "Automatic Display Enabled" -bool false`
echo "Disabling keyboard from automatically adjusting backlight brightness in low light...\c"
run_command `sudo defaults write /Library/Preferences/com.apple.iokit.AmbientLightSensor "Automatic Keyboard Enabled" -bool false`
################################################################################
# Screen Configurations #
################################################################################
echo ""
cecho $cyan "Screen Configurations..."
echo ""
echo "Requiring password immediately after sleep or screen saver begins...\c"
run_command `sudo defaults write com.apple.screensaver askForPassword -int 1`
echo "...and making it immediate...\c"
run_command `sudo defaults write com.apple.screensaver askForPasswordDelay -int 0`
echo ""
cecho $yellow "Where should screenshots be saved (~/Desktop is default)?" $no_r
# https://github.com/omgmog
read SCREENSHOT_LOCATION
# Default if nothing was entered
if [ -z "${SCREENSHOT_LOCATION}" ]; then
SCREENSHOT_LOCATION="${HOME}/Desktop"
else
# Assume a relative path if the first character is not a '/'
if [[ "${SCREENSHOT_LOCATION:0:1}" != "/" ]]; then
SCREENSHOT_LOCATION="${HOME}/${SCREENSHOT_LOCATION}"
fi
fi
echo "Setting screenshot location to '${SCREENSHOT_LOCATION}'...\c"
run_command `sudo defaults write com.apple.screencapture location -string "${SCREENSHOT_LOCATION}"`
echo ""
cecho $yellow "What format should screenshots be saved as? (hit ENTER for PNG, options: BMP, GIF, JPG, PDF, TIFF)?" $no_r
read SCREENSHOT_FORMAT
if [ -z "${SCREENSHOT_FORMAT}}" ]; then
SCREENSHOT_FORMAT="PNG"
fi
echo "Setting screenshot format to $SCREENSHOT_FORMAT...\c"
run_command `sudo defaults write com.apple.screencapture type -string "$SCREENSHOT_FORMAT"`
echo ""
echo "Enabling subpixel font rendering on non-Apple LCDs...\c"
run_command `sudo defaults write NSGlobalDomain AppleFontSmoothing -int 2`
echo "Enabling HiDPI display modes (requires restart)...\c"
run_command `sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true`
################################################################################
# Finder Configurations #
################################################################################
echo ""
cecho $cyan "Finder Configurations..."
echo ""
echo "Showing icons for hard drives, servers, and removable media on the desktop...\c"
run_command `sudo defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true`
echo "Showing hidden files in Finder by default...\c"
run_command `sudo defaults write com.apple.Finder AppleShowAllFiles -bool true`
echo "Showing dot files in Finder by default...\c"
run_command `sudo defaults write com.apple.finder AppleShowAllFiles TRUE`
echo "Showing all filename extensions in Finder by default...\c"
run_command `sudo defaults write NSGlobalDomain AppleShowAllExtensions -bool true`
echo "Showing status bar in Finder by default...\c"
run_command `sudo defaults write com.apple.finder ShowStatusBar -bool true`
echo "Displaying full POSIX path as Finder window title...\c"
run_command `sudo defaults write com.apple.finder _FXShowPosixPathInTitle -bool true`
echo "Disabling the warning when changing a file extension...\c"
run_command `sudo defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false`
echo "Using column view in all Finder windows by default...\c"
run_command `sudo defaults write com.apple.finder FXPreferredViewStyle Clmv`
echo "Avoiding creation of .DS_Store files on network volumes...\c"
run_command `sudo defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true`
################################################################################
# Dock and Mission Control Configurations #
################################################################################
echo ""
cecho $cyan "Dock and Mission Control Configurations..."
echo ""
echo "Setting the icon size of Dock items to 36 pixels for optimal size/screen-realestate...\c"
run_command `sudo defaults write com.apple.dock tilesize -int 36`
echo "Speeding up Mission Control animations...\c"
run_command `sudo defaults write com.apple.dock expose-animation-duration -float 0.1`
echo "...and grouping windows by application...\c"
run_command `sudo defaults write com.apple.dock "expose-group-by-app" -bool true`
echo ""
echo "Setting Dock to auto-hide...\c"
run_command `sudo defaults write com.apple.dock autohide -bool true`
echo "Removing the Dock auto-hide delay...\c"
run_command `sudo defaults write com.apple.dock autohide-delay -float 0`
echo "...and removing the time modifier for auto-hide...\c"
run_command `sudo defaults write com.apple.dock autohide-time-modifier -float 0`
################################################################################
# Sublime Text 3 Configuration #
################################################################################
echo ""
cecho $cyan "Sublime Text 3 Configuration"
echo ""
echo "Linking Sublime Text 3 for command line usage as 'subl'...\c"
run_command `sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl`
echo "Setting Git to use Sublime Text 3 as default editor...\c"
run_command `sudo git config --global core.editor "subl -n -w"`
################################################################################
# Kill Affected Applications #
################################################################################
echo ""
cecho $cyan "Done!"
echo ""
echo ""
cecho $red "############################################################"
cecho $red "# Some of these changes require a logout/restart to #"
cecho $red "# take effect. Killing some open applications in #"
cecho $red "# order to take effect. #"
cecho $red "############################################################"
echo ""
find ~/Library/Application\ Support/Dock -name "*.db" -maxdepth 1 -delete
for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
"Dock" "Finder" "Mail" "Messages" "Safari" "SystemUIServer" \
"Terminal" "Transmission"; do
killall "${app}" > /dev/null 2>&1
done
echo ""
cecho $red "Restart now."
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment