Skip to content

Instantly share code, notes, and snippets.

@ratazzi
Created March 28, 2015 13:35
Show Gist options
  • Save ratazzi/91fb1a75c19f707cadb9 to your computer and use it in GitHub Desktop.
Save ratazzi/91fb1a75c19f707cadb9 to your computer and use it in GitHub Desktop.
OS X 安装后的自动化设置
#!/usr/bin/env ruby
def abs_path(path)
File.symlink?(path) ? File.readlink(path) : path
end
apps = [
["/Library/Input Methods/Squirrel.app", "squirrel", false],
["{/,#{ENV['HOME']}/}Applications/Dropbox.app", "dropbox", false],
["{/,#{ENV['HOME']}/}Applications/Alfred 2.app", "alfred", false],
["{/,#{ENV['HOME']}/}Applications/Moom.app", "moom", false],
["{/,#{ENV['HOME']}/}Applications/BitTorrent Sync.app", "bittorrent-sync", false],
["/Applications/App Store.app", "", true],
["/Applications/iTunes.app", "", true],
["/Applications/Calendar.app", "", true],
["/Applications/Mail.app", "", true],
["/Applications/FaceTime.app", "", true],
["/Applications/Safari.app", "", true],
["{/,#{ENV['HOME']}/}Applications/Firefox.app", "firefox", true],
["{/,#{ENV['HOME']}/}Applications/Flux.app", "flux", false],
["{/,#{ENV['HOME']}/}Applications/Google Chrome.app", "", true],
["{/,#{ENV['HOME']}/}Applications/MacVim.app", "macvim", true],
["{/,#{ENV['HOME']}/}Applications/TextMate.app", "", true],
["{/,#{ENV['HOME']}/}Applications/Sublime Text.app", "", true],
["/Applications/Byword.app", "", true],
["/Applications/Utilities/Terminal.app", "", true],
["/Applications/Xcode.app", "", true],
["/Applications/Dash.app", "", true],
["/Applications/Server.app", "", true],
["/Applications/Parallels Desktop.app", "", true],
["/Applications/Preview.app", "", true],
["/Applications/Things.app", "", true],
["/Applications/QQ.app", "", true],
# ["{/,/#{ENV['HOME']}/}Applications/Foxmail.app", "", false],
["{/,#{ENV['HOME']}/}Applications/Keka.app", "keka", false],
["{/,#{ENV['HOME']}/}Applications/Postgres.app", "postgres", false],
["{/,#{ENV['HOME']}/}Applications/Karabiner.app", "karabiner", false],
["{/,#{ENV['HOME']}/}Applications/GitX.app", "gitx", false],
["{/,#{ENV['HOME']}/}Applications/iExplorer.app", "iexplorer", false],
["{/,#{ENV['HOME']}/}Applications/VirtualBox.app", "virtualbox", false],
["/usr/bin/vagrant", "vagrant", false],
["#{ENV['HOME']}/Library/PreferencePanes/Hazel.prefPane", "hazel", false],
["/Library/Internet Plug-Ins/Flash Player.plugin", "flash", false],
]
apps.map do |app|
app_path, package, dock = app
`proxychains4 brew cask install #{package}` if package.length > 0 and not Dir.glob(app_path).length > 0
end
`proxychains4 brew cask fetch google-chrome && hdiutil attach /Library/Caches/Homebrew/google-chrome-latest.dmg && cp -rf '/Volumes/Google Chrome/Google Chrome.app' /Applications/` unless File.exist?('/Applications/Google Chrome.app')
puts "\n>>> Applications\n"
`defaults write com.apple.dock persistent-apps -array ""`
apps.map do |app|
app_glob_path, package, dock = app
app_path = Dir.glob(app_glob_path)
`defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>#{abs_path(app_path.first)}</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"` if app_path.length > 0 and dock
puts " * #{abs_path(app_path.first)} \033[01;32m✓\033[00m" if app_path.length > 0
end
`killall Dock`
#!/bin/bash
echo ''
echo '88""Yb db 888888 db 8888P 8888P 88'
echo '88__dP dPYb 88 dPYb dP dP 88'
echo '88"Yb dP__Yb 88 dP__Yb dP dP 88'
echo '88 Yb dP""""Yb 88 dP""""Yb d8888 d8888 88'
echo ''
echo -e '\033[01;32m>>> Basic settings\033[00m'
defaults write NSGlobalDomain AppleFontSmoothing -integer 1
# {{{ Keyboard
echo ' * Setting Keyboard'
# Set a blazingly fast keyboard repeat rate
defaults write NSGlobalDomain KeyRepeat -int 1
# Set a shorter Delay until key repeat
defaults write NSGlobalDomain InitialKeyRepeat -int 15
# }}}
# {{{ Mouse and Trackpad
# Mouse: tracking speed
echo ' * Setting Mouse and Trackpad'
defaults write -g com.apple.mouse.scaling 2
defaults write -g com.apple.trackpad.scaling 1
# 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
# 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
# # Trackpad: three finder drag (not working)
# defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerDrag -bool true
# defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerDrag -bool true
# defaults -currentHost write NSGlobalDomain com.apple.trackpad.threeFingerSwipeGesture -int 1
osascript -e "$(curl -fsSL https://example.com/snippets/trackpad.scpt)" #trackpad
# Mouse: disable natural
defaults write -g com.apple.swipescrolldirection -bool false
# Language & Region
# defaults write com.apple.MenuBarClock Use24HourClock -bool true
echo ' * Setting Language & Region'
osascript -e "$(curl -fsSL https://example.com/snippets/localization.scpt)" #localization
# }}}
# {{{ Dock
echo ' * Setting Language & Region'
# Set the icon size of Dock items to 45 pixels
defaults write com.apple.dock tilesize -int 45
# Change magnification size of the Dock
defaults write com.apple.dock largesize -float 64
# Speed up Mission Control animations
defaults write com.apple.dock expose-animation-duration -float 0.07
# }}}
# {{{ Finder
echo ' * Setting Finder'
# Show all filename extensions in Finder
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Sidebar
osascript -e "$(curl -fsSL https://example.com/snippets/finder.scpt)" #finder
# Use current directory as default search scope in Finder
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Open new windows on the user's home
defaults write com.apple.finder NewWindowTarget -string "PfHm"
defaults write com.apple.finder NewWindowTargetPath -string "file://$HOME"
# }}}
# {{{ Safari
# Enable Safari debug menu
echo ' * Setting Safari'
defaults write com.apple.Safari IncludeDebugMenu 1
# }}}
# Check for software updates daily, not just once per week
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
# https://gist.github.com/nanoant/1244807
# https://github.com/Aeon/sidebarFinagler
# Enable ssh server
[ `netstat -an | grep '*.22' | grep tcp4 | grep LISTEN | wc -l` -ne 1 ] \
&& sudo systemsetup -f -setremotelogin on \
|| echo -e ' * OpenSSH Server \033[01;32m✓\033[00m'
# Enable sharing (not working)
# sudo sharing -e "ratazzi's Public Folder" -s 111 #sharing
# {{{ Internet
echo ''
echo -e '\033[01;32m>>> Internet\033[00m'
echo ''
[ ! -d "/Applications/GoAgentX.app" ] \
&& echo "* Downloading GoAgentX" \
&& curl -O https://goagentx.com/files/GoAgentX.dmg \
&& open ./GoAgentX.dmg \
&& echo "\033[01;33m * Please run GoAgentX then run this script again.\033[00m" && exit 0
[ `netstat -an | grep '*.8016' | grep tcp4 | grep LISTEN | wc -l` -eq 1 ] \
&& echo -e '* GoAgentX HTTP \033[01;32m✓\033[00m'
[ `netstat -an | grep '*.6666' | grep tcp4 | grep LISTEN | wc -l` -eq 1 ] \
&& echo -e '* GoAgentX SOCKS5 \033[01;32m✓\033[00m'
# }}}
# {{{ Homebrew and Apps
echo ''
echo -e '\033[01;32m>>> Homebrew and Apps\033[00m'
echo ''
# Homebrew
[ ! -x "/usr/local/bin/brew" ] \
&& echo ">>> Install Homebrew" \
&& ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew cask > /dev/null 2>&1
[ $? -ne 0 ] && echo '>>> Install Homebrew Cask' \
&& brew install caskroom/cask/brew-cask
brew install htop \
fish \
proxychains-ng \
md5sha1sum \
aria2 \
ctags \
dos2unix \
gettext \
mtr \
mutt \
netcat \
rlwrap \
tmux \
zsync \
ideviceinstaller \
ack \
boot2docker \
nmap \
tig \
sqlite \
tree \
watch \
siege \
ios-sim \
mosh
[ ! -x "/usr/local/bin/virtualenv" ] && sudo easy_install virtualenv
[ ! -s "$HOME/.runtime/bin" ] && virtualenv --system-site-packages $HOME/.runtime
$HOME/.runtime/bin/pip install --upgrade pip \
&& $HOME/.runtime/bin/pip install --index-url http://pypi.douban.com/simple $(curl -fsSL https://example.com/snippets/requirements.txt)
[ ! -d "$HOME/.config" ] && mkdir "$HOME/.config"
ruby -e "$(curl -fsSL https://example.com/snippets/symlink.rb)"
[ ! -s "$HOME/.rvm/scripts/rvm" ] \
&& echo ">>> Install rvm" \
&& curl -sSL https://get.rvm.io | bash -s stable \
&& rvm install ruby-head \
&& gem source -r https://rubygems.org/ \
&& gem source -a https://ruby.taobao.org
[ `netstat -an | grep '*.8016' | grep tcp4 | grep LISTEN | wc -l` -ne 1 ] \
&& echo -e "\033[01;33m * proxychains4 is not available yet.\033[00m" && exit 0
# }}}
# Remove all the icons in the Dock
ruby -e "$(curl -fsSL https://example.com/snippets/apps.rb)" #dock
# Input method
# ~/Library/Preferences/com.apple.HIToolbox.plist
ruby -e "$(curl -fsSL https://example.com/snippets/input_method.rb)" #input source
[ $? -eq 0 ] && echo -e "\n\033[01;32m * Enjoy.\033[00m\n"
exit 0
tell application "System Preferences"
activate
set current pane to pane "com.apple.Localization"
end tell
tell application "System Events"
tell application process "System Preferences"
tell group 1 of window "Language & Region"
tell checkbox "24-Hour Time" to if value is 0 then click
end tell
end tell
end tell
tell application "System Preferences"
activate
set current pane to pane "com.apple.preferences.sharing"
end tell
tell application "System Events"
tell process "System Preferences"
delay 2
tell window "Sharing"
tell (checkbox 1 of row 2 of table 1 of scroll area 1 of group 1) to if value is 0 then click
delay 1
end tell
end tell
end tell
tell application "System Events" to tell process "SystemUIServer"
tell (menu bar item 1 of menu bar 1 whose description is "text input")
# !! Sadly, we must *visibly* select (open) the text-input menu-bar extra in order to
# !! populate its menu with the available input sources.
select
tell menu 1
# !! Curiously, using just 'name' instead of '(get name)' didn't work: 'Access not allowed'.
click (first menu item whose title = "Squirrel")
delay 0.5
tell application "System Events" to keystroke "`" using {control down, option down}
end tell
end tell
end tell
# Trackpad: three finder drag
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.trackpad"
end tell
tell application "System Events"
tell application process "System Preferences"
tell tab group 1 of window "Trackpad"
click radio button "Point & Click"
tell checkbox 4 to if value is 0 then click -- checkbox was not checked.
end tell
end tell
end tell
tell application "System Preferences" to quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment