PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/macos/set-defaults.sh

https://gitlab.com/rrevanth/dotfiles
Shell | 339 lines | 276 code | 46 blank | 17 comment | 10 complexity | 0796da7d4f009a6c9a032295aed1ea58 MD5 | raw file
  1. #!/bin/sh
  2. # Sets reasonable macOS defaults.
  3. #
  4. # Or, in other words, set shit how I like in macOS.
  5. #
  6. # The original idea (and a couple settings) were grabbed from:
  7. # https://github.com/mathiasbynens/dotfiles/blob/master/.osx
  8. # More from:
  9. # https://gist.github.com/brandonb927/3195465
  10. #
  11. # Run ./set-defaults.sh and you'll be good to go.
  12. if [ "$(uname -s)" != "Darwin" ]; then
  13. exit 0
  14. fi
  15. set +e
  16. disable_agent() {
  17. mv "$1" "$1_DISABLED" >/dev/null 2>&1 \
  18. || sudo mv "$1" "$1_DISABLED" >/dev/null 2>&1
  19. }
  20. unload_agent() {
  21. launchctl unload -w "$1" >/dev/null 2>&1
  22. }
  23. test -z "$TRAVIS_JOB_ID" && sudo -v
  24. echo ""
  25. echo "› System:"
  26. echo " › Disable press-and-hold for keys in favor of key repeat"
  27. defaults write -g ApplePressAndHoldEnabled -bool false
  28. echo " › Use AirDrop over every interface"
  29. defaults write com.apple.NetworkBrowser BrowseAllInterfaces 1
  30. echo " › Show the ~/Library folder"
  31. chflags nohidden ~/Library
  32. echo " › Show the /Volumes folder"
  33. sudo chflags nohidden /Volumes
  34. echo " › Set a really fast key repeat"
  35. defaults write NSGlobalDomain KeyRepeat -int 2
  36. defaults write NSGlobalDomain InitialKeyRepeat -int 15
  37. echo " › Disable transparency"
  38. defaults write com.apple.universalaccess reduceTransparency -bool true
  39. echo " › Enable text replacement almost everywhere"
  40. defaults write -g WebAutomaticTextReplacementEnabled -bool true
  41. echo " › Turn off keyboard illumination when computer is not used for 5 minutes"
  42. defaults write com.apple.BezelServices kDimTime -int 300
  43. echo " › Require password immediately after sleep or screen saver begins"
  44. defaults write com.apple.screensaver askForPassword -int 1
  45. defaults write com.apple.screensaver askForPasswordDelay -int 0
  46. echo " › Always show scrollbars"
  47. defaults write NSGlobalDomain AppleShowScrollBars -string "Always"
  48. # Possible values: `WhenScrolling`, `Automatic` and `Always`
  49. echo " › Disable Dashboard"
  50. defaults write com.apple.dashboard mcx-disabled -bool true
  51. echo " › Don't automatically rearrange Spaces based on most recent use"
  52. defaults write com.apple.dock mru-spaces -bool false
  53. echo " › Increase the window resize speed for Cocoa applications"
  54. defaults write NSGlobalDomain NSWindowResizeTime -float 0.001
  55. echo " › Disable smart quotes and smart dashes as they're annoying when typing code"
  56. defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
  57. defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
  58. echo " › Disable auto-correct"
  59. defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
  60. echo " › Set up trackpad & mouse speed to a reasonable number"
  61. defaults write -g com.apple.trackpad.scaling 2
  62. defaults write -g com.apple.mouse.scaling 2.5
  63. echo " › Avoid the creation of .DS_Store files on network volumes"
  64. defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
  65. echo " › Disable the 'Are you sure you want to open this application?' dialog"
  66. defaults write com.apple.LaunchServices LSQuarantine -bool false
  67. echo " › Set dark interface style"
  68. defaults write NSGlobalDomain AppleInterfaceStyle -string "Dark"
  69. echo " › Set graphite appearance"
  70. defaults write NSGlobalDomain AppleAquaColorVariant -int 6
  71. echo " › Set graphite highlight color"
  72. defaults write NSGlobalDomain AppleHighlightColor -string "0.847059 0.847059 0.862745"
  73. echo " › Show battery percent"
  74. defaults write com.apple.menuextra.battery ShowPercent -bool true
  75. if [ ! -z "$TRAVIS_JOB_ID" ]; then
  76. echo " › Speed up wake from sleep to 24 hours from an hour"
  77. # http://www.cultofmac.com/221392/quick-hack-speeds-up-retina-macbooks-wake-from-sleep-os-x-tips/
  78. sudo pmset -a standbydelay 86400
  79. fi
  80. echo " › Removing duplicates in the 'Open With' menu"
  81. /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
  82. -kill -r -domain local -domain system -domain user
  83. #############################
  84. echo ""
  85. echo "› Finder:"
  86. echo " › Always open everything in Finder's list view"
  87. defaults write com.apple.Finder FXPreferredViewStyle Nlsv
  88. echo " › Set the Finder prefs for showing a few different volumes on the Desktop"
  89. defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
  90. defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
  91. echo " › Expand save panel by default"
  92. defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
  93. echo " › Set sidebar icon size to small"
  94. defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 1
  95. echo " › Show status bar"
  96. defaults write com.apple.finder ShowStatusBar -bool true
  97. echo " › Show path bar"
  98. defaults write com.apple.finder ShowPathbar -bool true
  99. echo " › Disable the warning before emptying the Trash"
  100. defaults write com.apple.finder WarnOnEmptyTrash -bool false
  101. echo " › Save to disk by default, instead of iCloud"
  102. defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
  103. echo " › Display full POSIX path as Finder window title"
  104. defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
  105. echo " › Disable the warning when changing a file extension"
  106. defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
  107. #############################
  108. echo ""
  109. echo "› Photos:"
  110. echo " › Disable it from starting everytime a device is plugged in"
  111. defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
  112. #############################
  113. echo ""
  114. echo "› Browsers:"
  115. echo " › Hide Safari's bookmark bar"
  116. defaults write com.apple.Safari ShowFavoritesBar -bool false
  117. echo " › Set up Safari for development"
  118. defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
  119. defaults write com.apple.Safari IncludeDevelopMenu -bool true
  120. defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
  121. defaults write com.apple.Safari "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled" -bool true
  122. defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
  123. echo " › Disable the annoying backswipe in Chrome"
  124. defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false
  125. #############################
  126. echo ""
  127. echo "› Dock"
  128. echo " › Setting the icon size of Dock items to 36 pixels for optimal size/screen-realestate"
  129. defaults write com.apple.dock tilesize -int 36
  130. echo " › Speeding up Mission Control animations and grouping windows by application"
  131. defaults write com.apple.dock expose-animation-duration -float 0.1
  132. defaults write com.apple.dock "expose-group-by-app" -bool true
  133. echo " › Remove the auto-hiding Dock delay"
  134. defaults write com.apple.dock autohide-delay -float 0
  135. echo " › Remove the animation when hiding/showing the Dock"
  136. defaults write com.apple.dock autohide-time-modifier -float 0
  137. echo " › Automatically hide and show the Dock"
  138. defaults write com.apple.dock autohide -bool true
  139. echo " › Don't animate opening applications from the Dock"
  140. defaults write com.apple.dock launchanim -bool false
  141. #############################
  142. echo ""
  143. echo "› Transmission:"
  144. echo " › Use ~/Downloads/Incomplete to store incomplete downloads"
  145. defaults write org.m0k.transmission UseIncompleteDownloadFolder -bool true
  146. defaults write org.m0k.transmission IncompleteDownloadFolder -string "$HOME/Downloads/Incomplete"
  147. echo " › Don't prompt for confirmation before downloading"
  148. defaults write org.m0k.transmission DownloadAsk -bool false
  149. echo " › Trash original torrent files"
  150. defaults write org.m0k.transmission DeleteOriginalTorrent -bool true
  151. echo " › Hide the donate message"
  152. defaults write org.m0k.transmission WarningDonate -bool false
  153. echo " › Hide the legal disclaimer"
  154. defaults write org.m0k.transmission WarningLegal -bool false
  155. echo " › Auto-add .torrent files in ~/Downloads"
  156. defaults write org.m0k.transmission AutoImportDirectory -string "$HOME/Downloads"
  157. echo " › Auto-resize the window to fit transfers"
  158. defaults write org.m0k.transmission AutoSize -bool true
  159. echo " › Auto update to betas"
  160. defaults write org.m0k.transmission AutoUpdateBeta -bool true
  161. echo " › Set up the best block list"
  162. defaults write org.m0k.transmission EncryptionRequire -bool true
  163. defaults write org.m0k.transmission BlocklistAutoUpdate -bool true
  164. defaults write org.m0k.transmission BlocklistNew -bool true
  165. defaults write org.m0k.transmission BlocklistURL -string "http://john.bitsurge.net/public/biglist.p2p.gz"
  166. #############################
  167. echo ""
  168. echo "› Mail:"
  169. echo " › Add the keyboard shortcut CMD + Enter to send an email"
  170. defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Send" "@\U21a9"
  171. # shellcheck disable=SC2016
  172. defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Archive" '@$e'
  173. echo " › Disable smart quotes as it's annoying for messages that contain code"
  174. defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticQuoteSubstitutionEnabled" -bool false
  175. echo " › Set email addresses to copy as 'foo@example.com' instead of 'Foo Bar <foo@example.com>'"
  176. defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false
  177. echo " › Display emails in threaded mode, sorted by date (oldest at the top)"
  178. defaults write com.apple.mail DraftsViewerAttributes -dict-add "DisplayInThreadedMode" -string "yes"
  179. defaults write com.apple.mail DraftsViewerAttributes -dict-add "SortedDescending" -string "yes"
  180. defaults write com.apple.mail DraftsViewerAttributes -dict-add "SortOrder" -string "received-date"
  181. echo " › Disable inline attachments (just show the icons)"
  182. defaults write com.apple.mail DisableInlineAttachmentViewing -bool true
  183. echo " › Disable automatic spell checking"
  184. defaults write com.apple.mail SpellCheckingBehavior -string "NoSpellCheckingEnabled"
  185. echo " › Disable send and reply animations in Mail.app"
  186. defaults write com.apple.mail DisableReplyAnimations -bool true
  187. defaults write com.apple.mail DisableSendAnimations -bool true
  188. #############################
  189. echo ""
  190. echo "› Time Machine:"
  191. echo " › Prevent Time Machine from prompting to use new hard drives as backup volume"
  192. defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
  193. ###############################################################################
  194. # SSD-specific tweaks #
  195. ###############################################################################
  196. if [ ! -z "$TRAVIS_JOB_ID" ] && diskutil info disk0 | grep SSD >/dev/null 2>&1; then
  197. echo " › Disable local backups"
  198. # https://classicyuppie.com/what-crap-is-this-os-xs-mobilebackups/
  199. sudo tmutil disablelocal
  200. echo " › Disable hibernation (speeds up entering sleep mode)"
  201. sudo pmset -a hibernatemode 0
  202. echo " › Remove the sleep image file to save disk space"
  203. sudo rm /private/var/vm/sleepimage
  204. echo " › Create a zero-byte file instead..."
  205. sudo touch /private/var/vm/sleepimage
  206. echo " › ...and make sure it can’t be rewritten"
  207. sudo chflags uchg /private/var/vm/sleepimage
  208. echo " › Disable the sudden motion sensor as it’s not useful for SSDs"
  209. sudo pmset -a sms 0
  210. fi
  211. #############################
  212. echo ""
  213. echo "› Media:"
  214. if [ -z "$KEEP_ITUNES" ]; then
  215. echo " › Disable iTunes helper"
  216. disable_agent /Applications/iTunes.app/Contents/MacOS/iTunesHelper.app
  217. echo " › Prevent play button from launching iTunes"
  218. unload_agent /System/Library/LaunchAgents/com.apple.rcd.plist
  219. fi
  220. echo " › Disable Spotify web helper"
  221. disable_agent ~/Applications/Spotify.app/Contents/MacOS/SpotifyWebHelper
  222. echo " › Prevent Android-File-Transfer to open when a device connects"
  223. disable_agent "/Applications/Android File Transfer.app/Contents/Resources/Android File Transfer Agent.app"
  224. disable_agent "$HOME/Library/Application Support/Google/Android File Transfer/Android File Transfer Agent.app"
  225. #############################
  226. echo ""
  227. echo "› Twitter.app:"
  228. echo " › Disable smart quotes as it’s annoying for code tweets"
  229. defaults write com.twitter.twitter-mac AutomaticQuoteSubstitutionEnabled -bool false
  230. echo " › Show the app window when clicking the menu bar icon"
  231. defaults write com.twitter.twitter-mac MenuItemBehavior -int 1
  232. echo " › Enable the hidden ‘Develop’ menu"
  233. defaults write com.twitter.twitter-mac ShowDevelopMenu -bool true
  234. echo " › Open links in the background"
  235. defaults write com.twitter.twitter-mac openLinksInBackground -bool true
  236. echo " › Allow closing the new tweet window by pressing Esc"
  237. defaults write com.twitter.twitter-mac ESCClosesComposeWindow -bool true
  238. echo " › Show full names rather than Twitter handles"
  239. defaults write com.twitter.twitter-mac ShowFullNames -bool true
  240. echo " › Hide the app in the background if it’s not the front-most window"
  241. defaults write com.twitter.twitter-mac HideInBackground -bool true
  242. #############################
  243. echo ""
  244. echo "› Kill related apps"
  245. for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
  246. "Dock" "Finder" "Mail" "Messages" "Safari" "SystemUIServer" \
  247. "Terminal" "Transmission" "Photos"; do
  248. killall "$app" >/dev/null 2>&1
  249. done
  250. set -e