Table of Contents

MacOS defaults

Hostname

# show:
for n in ComputerName HostName LocalHostName; do echo "$n = $(scutil --get $n)"; done
 
# set new hostname:
host=newname; dom=example.lan
for n in ComputerName LocalHostName; do sudo scutil --set $n $host; done
sudo scutil --set HostName $host.$dom

Keyboard layout

If the keyboard layout gets lost and reverts to US on boot, configure it as you want and then import your user keyboard settings to the default system settings with sudo :

sudo defaults import com.apple.HIToolbox.plist ~/Library/Preferences/com.apple.HIToolbox.plist

Default shell

List available shells: cat /etc/shells

Change the default shell to Bash:

chsh -s /bin/bash
# or
# chsh -s /usr/local/bin/bash

Also, to stop seeing Apple's warning to use zsh, add the following line to ~/.bash_profile (or ~/.profile ?):

export BASH_SILENCE_DEPRECATION_WARNING=1

So:

echo export BASH_SILENCE_DEPRECATION_WARNING=1 | tee .profile

Various settings

Bash defaults

Add to ~/.profile :

# Prompt color
export PS1='\[\e]2; \h: $PWD \a\e[32;1m\]$PWD/$\[\e[0m\] '
# History
export HISTSIZE=2000
export HISTTIMEFORMAT='%F %T '
# Additional path for scripts
PATH=/Users/Shared/bin:$PATH

Other examples from https://github.com/Integralist/dotfiles/blob/cc906bd14636543e71d9c034d6507f5986a80bbd/bootstrap.sh#L7-L53

# Enable hidden files in Finder (use toggle_hidden function from ~/.bashrc)
defaults write com.apple.finder AppleShowAllFiles YES
 
# Show all file extensions in Finder
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
 
# Decrease delay between repeated keys
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
defaults write NSGlobalDomain KeyRepeat -int 0
defaults write NSGlobalDomain InitialKeyRepeat -int 10
 
# Disable smart quotes and dashes
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
defaults write com.apple.TextEdit SmartQuotes -bool false
defaults write com.apple.TextEdit SmartDashes -bool false
 
# Configure menu bar clock to something useful
defaults write com.apple.menuextra.clock "DateFormat" "EEE d MMM  HH:mm:ss"
defaults write com.apple.menuextra.clock "FlashDateSeparators" 0
defaults write com.apple.menuextra.clock "IsAnalog" 0
 
# Configure Mouse Seconday Button
defaults write com.apple.mouse "enableSecondaryClick" 1
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse MouseButtonMode -string "TwoButton"

SMB shares

Disable "You are attempting to connect to the server ..." prompt

sudo defaults write /Library/Preferences/com.apple.NetworkAuthorization AllowUnknownServers -bool YES

Spotlight

Show if Spotlight indexing is enabled on the connected disks:

mdutil -s /Volumes/*

Disable it on a specific disk:

touch /Volumes/YOUR_DISK/.metadata_never_index

or

sudo mdutil -i off /Volumes/YOUR_DISK

Disable it globally (some people on the web say it shouldn't be done globally...):

sudo mdutil -a -i off

or

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

To re-enabe it:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

or

  sudo mdutil -a -i on

or for a specific disk:

  sudo mdutil -i on /Volumes/YOUR_DISK