Skip to content

Instantly share code, notes, and snippets.

@codenyte
Last active December 24, 2022 20:14
Show Gist options
  • Save codenyte/a9a8cd127e9952c7767b2859e09ce1f8 to your computer and use it in GitHub Desktop.
Save codenyte/a9a8cd127e9952c7767b2859e09ce1f8 to your computer and use it in GitHub Desktop.
My macOS Configuration Script
#!/usr/bin/env sh
#
# ___ ____
# _ __ ___ __ _ ___ / _ \/ ___|
# | '_ ` _ \ / _` |/ __| | | \___ \
# | | | | | | (_| | (__| |_| |___) |
# |_| |_| |_|\__,_|\___|\___/|____/
#
# ____ __ _ _ _
# / ___|___ _ __ / _(_) __ _ _ _ _ __ __ _| |_(_) ___ _ __
# | | / _ \| '_ \| |_| |/ _` | | | | '__/ _` | __| |/ _ \| '_ \
# | |__| (_) | | | | _| | (_| | |_| | | | (_| | |_| | (_) | | | |
# \____\___/|_| |_|_| |_|\__, |\__,_|_| \__,_|\__|_|\___/|_| |_|
# |___/
# ____ _ _
# / ___| ___ _ __(_)_ __ | |_
# \___ \ / __| '__| | '_ \| __|
# ___) | (__| | | | |_) | |_
# |____/ \___|_| |_| .__/ \__|
# |_|
#
# This script changes many settings in macOS to my personal preference, I do not reccomend to run the entire script, rather, just look through it and copy-paste the commands for the individual settings that you find useful into a terminal and run them. You might have to restart your Mac after disabling Disk warnings and killing the "diskarbitrationd" process.
# Note: This script only changes settings in macOS and default macOS Apps, not in 3rd-Party Apps. I have a seperate script for that.
#
#
#
# Table of Content
#
# Preparation
# General
# Finder
# Dock and Mission Control
# Safari and WebKit
# Xcode
# Music
# Photos
# Privacy
#
#
#
# Inspired by:
# https://github.com/geerlingguy/dotfiles/blob/master/.osx
# https://github.com/igorkulman/dotfiles/blob/main/.macos
# https://github.com/mathiasbynens/dotfiles/blob/main/.macos
# https://macos-defaults.com/
#
# _ _ _
# | \ | |_ _| |_ ___
# | \| | | | | __/ _ \
# | |\ | |_| | || __/
# |_| \_|\__, |\__\___|
# |___/
#
# Preparation
# Close any open System Preferences panes, to prevent them from overriding
# settings we’re about to change
osascript -e 'tell application "System Preferences" to quit'
# General
# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Expand print panel by default
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# Expand the following File Info panes:
# “General”, “Open with”, and “Sharing & Permissions”
defaults write com.apple.finder FXInfoPanesExpanded -dict \
General -bool true \
OpenWith -bool true \
Privileges -bool true
# Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Disable smart quotes as they’re annoying when typing code
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Disable smart dashes as they’re annoying when typing code
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Disable “Are you sure you want to open this application?” application quarantine message
defaults write com.apple.LaunchServices "LSQuarantine" -bool "false"
# Disable Screenshot Shadows
defaults write com.apple.screencapture "disable-shadow" -bool "true"
# Save screenshots in PNG format (other options: BMP, GIF, JPG, PDF, TIFF)
defaults write com.apple.screencapture type -string "png"
# Finder
# Show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# Show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Make document-proxy icon appear immediately when hovering over the toolbar
defaults write NSGlobalDomain "NSToolbarTitleViewRolloverDelay" -float "0"
# Finder: allow text selection in Quick Look
defaults write com.apple.finder QLEnableTextSelection -bool true
# 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"
# Show all file extensions by default
defaults write NSGlobalDomain "AppleShowAllExtensions" -bool "true"
# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Avoid creating .DS_Store files on network volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
# Avoid creating .DS_Store files on USB volumes
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Enable snap-to-grid for icons on the desktop and in other icon views
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
# Set the size of icons on the desktop and in other icon views
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:iconSize 56" ~/Library/Preferences/com.apple.finder.plist
# Show icons for hard drives, servers, and removable media on the desktop
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
# Show the ~/Library folder
chflags nohidden ~/Library
# Show the /Volumes folder
sudo chflags nohidden /Volumes
# Don't suggest new connected external drives for Time Machine backups
defaults write com.apple.TimeMachine "DoNotOfferNewDisksForBackup" -bool "true"
# Turn off Disk Warning
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.DiskArbitration.diskarbitrationd.plist DADisableEjectNotification -bool YES
# Disable disk image verification
defaults write com.apple.frameworks.diskimages skip-verify -bool true
defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true
defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true
# 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
# Dock and Mission Control
# Set the icon size of Dock items
defaults write com.apple.dock tilesize -int 48
# Set Dock auto-hide delay to 0
defaults write com.apple.dock autohide-delay -float 0
# Set Dock animation duration to 1
defaults write com.apple.dock autohide-time-modifier -int 1
# Speed up Mission Control animations
defaults write com.apple.dock expose-animation-duration -float 0.1
# Disable recent applications in the Dock
defaults write com.apple.dock "show-recents" -bool "false"
# Make Hidden Apps Transparent
defaults write com.apple.Dock showhidden -bool TRUE
# Top Left
defaults write com.apple.dock wvous-tl-corner -int 2
defaults write com.apple.dock wvous-tl-modifier -int 0
# Top Right
defaults write com.apple.dock wvous-tr-corner -int 12
defaults write com.apple.dock wvous-tr-modifier -int 0
# Bottom Left
defaults write com.apple.dock wvous-bl-corner -int 11
defaults write com.apple.dock wvous-bl-modifier -int 0
# Bottom Right
defaults write com.apple.dock wvous-br-corner -int 4
defaults write com.apple.dock wvous-br-modifier -int 0
# Disable automatic Spaces rearrangement
defaults write com.apple.dock "mru-spaces" -bool "false"
# Safari and WebKit
# Enable 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
# Add a context menu item for showing the Web Inspector in web views
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
# Press Tab to highlight each item on a web page
defaults write com.apple.Safari WebKitTabToLinksPreferenceKey -bool true
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2TabsToLinks -bool true
# Show the full URL in the address bar (note: this still hides the scheme)
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
# Prevent Safari from opening ‘safe’ files automatically after downloading
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
# Disable Safari’s thumbnail cache for History and Top Sites
defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2
# Make Safari’s search banners default to Contains instead of Starts With
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
# Disable AutoFill
defaults write com.apple.Safari AutoFillFromAddressBook -bool false
defaults write com.apple.Safari AutoFillPasswords -bool false
defaults write com.apple.Safari AutoFillCreditCardData -bool false
defaults write com.apple.Safari AutoFillMiscellaneousForms -bool false
# Disable Java
defaults write com.apple.Safari WebKitJavaEnabled -bool false
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled -bool false
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabledForLocalFiles -bool false
# Block pop-up windows
defaults write com.apple.Safari WebKitJavaScriptCanOpenWindowsAutomatically -bool false
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaScriptCanOpenWindowsAutomatically -bool false
# Xcode
# Show Xcode build time
defaults write com.apple.dt.Xcode ShowBuildOperationDuration -bool YES
# Show Xcode indexing files count
defaults write com.apple.dt.Xcode IDEIndexerActivityShowNumericProgress -bool true
# Add iOS & Watch Simulator to Launchpad
sudo ln -sf "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app" "/Applications/Simulator.app"
sudo ln -sf "/Applications/Xcode.app/Contents/Developer/Applications/Simulator (Watch).app" "/Applications/Simulator (Watch).app"
# Music
# Display a notification when a new song starts in the Music app
defaults write com.apple.Music "userWantsPlaybackNotifications" -bool "true"
# make sure to also enable notifications for music in system preferences, otherwise it won't work
# Photos
# Prevent Photos from opening automatically when devices are plugged in
defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
# Privacy
# Don’t send search queries to Apple
defaults write com.apple.Safari UniversalSearchEnabled -bool false
defaults write com.apple.Safari SuppressSearchSuggestions -bool true
# Disable personalized ads
defaults write com.apple.AdLib allowApplePersonalizedAdvertising -int 0
# Kill effected Applications
killall Dock; killall Finder; killall Safari; killall Music; killall Xcode; sudo pkill diskarbitrationd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment