/awesome-macos-command-line

Use your macOS terminal shell to do awesome things.

Creative Commons Attribution Share Alike 4.0 InternationalCC-BY-SA-4.0

Awesome macOS Command Line

A curated list of shell commands and tools specific to OS X.

“You don’t have to know everything. You simply need to know where to find it when necessary.” (John Brunner)

Awesome

If you want to contribute, you are highly encouraged to do so. Please read the contribution guidelines.

For more terminal shell goodness, please also see this list's sister list Awesome Command Line Apps.

Caffeinating

When you find something helpful in here, you could buy me a coffee. I spend a lot of time and effort on curating this list. Keeping me properly caffeinated accelerates things. And it would really make my day. Kindness of strangers and all that. If you can't or won't, no hard feelings. It's available completely free for a reason. Still, it would be awesome.

https://github.com/sponsors/herrbischoff

Foreword

There's really only one thing I'd like to note here: man pages. Man pages. Man pages. Okay, three things. But this one thing seemed so important, I had to mention it multiple times. If you're not doing it already, you should get into the habit of consulting man pages before searching anywhere else. Unix-style man pages are an excellent source of documentation. There's even a man page for the man command itself:

man man

It also explains what the numbers in the man pages refer to --- like man(1).

Contents

Applications

Safari

Develop Menu and Web Inspector

# Enable
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true && \
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 && \
defaults write -g WebKitDeveloperExtras -bool true

# Disable (Default)
defaults delete com.apple.Safari IncludeInternalDebugMenu && \
defaults delete com.apple.Safari IncludeDevelopMenu && \
defaults delete com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey && \
defaults delete com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled && \
defaults delete -g WebKitDeveloperExtras

TextEdit

Use Plain Text Mode as Default

defaults write com.apple.TextEdit RichText -int 0

Developer

Vim

Neovim

Install the modern Vim drop-in alternative via Homebrew.

brew install neovim

Xcode

Install Command Line Tools without Xcode

xcode-select --install

Remove All Unavailable Simulators

xcrun simctl delete unavailable

Files, Disks and Volumes

Show All Attached Disks and Partitions

diskutil list

Disk Images

Create Disk Image From Folder Contents

hdiutil create -volname "Volume Name" -srcfolder /path/to/folder -ov diskimage.dmg

If you'd like to encrypt the disk image:

hdiutil create -encryption -stdinpass -volname "Volume Name" -srcfolder /path/to/folder -ov encrypted.dmg

By default, you'll be prompted for a password. You can automate that by piping in a password:

echo -n YourPassword | hdiutil create -encryption -stdinpass -volname "Volume Name" -srcfolder /path/to/folder -ov encrypted.dmg

Mount Disk Image

hdiutil attach /path/to/diskimage.dmg

Unmount Disk Image

hdiutil detach /dev/disk2s1

Finder

Files and Folders

Clear All ACLs

sudo chmod -RN /path/to/folder

Hide Folder in Finder

chflags hidden /path/to/folder/

Show All File Extensions

defaults write -g AppleShowAllExtensions -bool true

Set Protected Flag

This is equivalent to Finder "Locked" status.

# Disable (Default)
sudo chflags -R nouchg /path/to/file/or/folder

# Enable
sudo chflags -R uchg /path/to/file/or/folder

Show Hidden Files

# Show All
defaults write com.apple.finder AppleShowAllFiles true

# Restore Default File Visibility
defaults write com.apple.finder AppleShowAllFiles false

Show Full Path in Finder Title

defaults write com.apple.finder _FXShowPosixPathInTitle -bool true

Unhide User Library Folder

chflags nohidden ~/Library

Increase Number of Recent Places

defaults write -g NSNavRecentPlacesLimit -int 10 && \
killall Finder

Layout

Show "Quit Finder" Menu Item

Makes possible to see Finder menu item "Quit Finder" with default shortcut Cmd + Q

# Enable
defaults write com.apple.finder QuitMenuItem -bool true && \
killall Finder

# Disable (Default)
defaults write com.apple.finder QuitMenuItem -bool false && \
killall Finder

Smooth Scrolling

Useful if you’re on an older Mac that messes up the animation.

# Disable
defaults write -g NSScrollAnimationEnabled -bool false

# Enable (Default)
defaults write -g NSScrollAnimationEnabled -bool true

Rubberband Scrolling

# Disable
defaults write -g NSScrollViewRubberbanding -bool false

# Enable (Default)
defaults write -g NSScrollViewRubberbanding -bool true

Expand Save Panel by Default

defaults write -g NSNavPanelExpandedStateForSaveMode -bool true && \
defaults write -g NSNavPanelExpandedStateForSaveMode2 -bool true

Desktop Icon Visibility

# Hide Icons
defaults write com.apple.finder CreateDesktop -bool false && \
killall Finder

# Show Icons (Default)
defaults write com.apple.finder CreateDesktop -bool true && \
killall Finder

Path Bar

# Show
defaults write com.apple.finder ShowPathbar -bool true

# Hide (Default)
defaults write com.apple.finder ShowPathbar -bool false

Scrollbar Visibility

Possible values: WhenScrolling, Automatic and Always.

defaults write -g AppleShowScrollBars -string "Always"

Status Bar

# Show
defaults write com.apple.finder ShowStatusBar -bool true

# Hide (Default)
defaults write com.apple.finder ShowStatusBar -bool false

Save to Disk by Default

Sets default save target to be a local disk, not iCloud.

defaults write -g NSDocumentSaveNewDocumentsToCloud -bool false

Set Current Folder as Default Search Scope

defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"

Set Default Finder Location to Home Folder

defaults write com.apple.finder NewWindowTarget -string "PfLo" && \
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}"

Set Sidebar Icon Size

Sets size to 'medium'.

defaults write -g NSTableViewDefaultSizeMode -int 2

Metadata Files

Disable Creation of Metadata Files on Network Volumes

Avoids creation of .DS_Store and AppleDouble files.

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

Disable Creation of Metadata Files on USB Volumes

Avoids creation of .DS_Store and AppleDouble files.

defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true

Opening Things

Change Working Directory to Finder Path

If multiple windows are open, it chooses the top-most one.

cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"

Open URL

open https://github.com

Open File

open README.md

Open Applications

You can open applications using -a.

open -a "Google Chrome" https://github.com

Open Folder

open /path/to/folder/

Open Current Folder

open .

Functions

Please see this file.

Hardware

Power Management

Prevent System Sleep

Prevent sleep for 1 hour:

caffeinate -u -t 3600

Chime When Charging

Play iOS charging sound when MagSafe is connected.

# Enable
defaults write com.apple.PowerChime ChimeOnAllHardware -bool true && \
open /System/Library/CoreServices/PowerChime.app

# Disable (Default)
defaults write com.apple.PowerChime ChimeOnAllHardware -bool false && \
killall PowerChime

Input Devices

Keyboard

Auto-Correct

# Disable
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false

# Enable (Default)
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool true

# Show Status
defaults read -g NSAutomaticSpellingCorrectionEnabled

Full Keyboard Access

Enable Tab in modal dialogs.

# Text boxes and lists only (Default)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 0

# All controls
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

Key Repeat

Change the "press and hold" behavior.

# Enable
defaults write -g ApplePressAndHoldEnabled -bool false

# Disable (Default)
defaults write -g ApplePressAndHoldEnabled -bool true

Key Repeat Rate

Sets a very fast repeat rate, adjust to taste.

defaults write -g KeyRepeat -int 0.02

Launchpad

Reset Launchpad Layout

You need to restart Dock because Launchpad is tied to it.

# Up to OS X 10.10 (Yosemite)
rm ~/Library/Application\ Support/Dock/*.db && \
killall Dock

# From OS X 10.11 (El Capitan)
defaults write com.apple.dock ResetLaunchPad -bool true && \
killall Dock

Media

Audio

Convert Audio File to iPhone Ringtone

afconvert input.mp3 ringtone.m4r -f m4af

Create Audiobook From Text

Uses "Alex" voice, a plain UTF-8 encoded text file for input and AAC output.

say -v Alex -f file.txt -o "output.m4a"

Disable Sound Effects on Boot

sudo nvram SystemAudioVolume=" "

Mute Audio Output

osascript -e 'set volume output muted true'

Set Audio Volume

osascript -e 'set volume 4'

Play Audio File

You can play all audio formats that are natively supported by QuickTime.

afplay -q 1 filename.mp3

Speak Text with System Default Voice

say 'All your base are belong to us!'

Startup Chime

Older Macs:

# Enable (Default)
sudo nvram BootAudio=%01

# Disable
sudo nvram BootAudio=%00

From 2016 models on:

# Enable
sudo nvram StartupMute=%00

# Disable (Default)
sudo nvram StartupMute=%01

Video

Auto-Play Videos in QuickTime Player

defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 1

Networking

Bonjour

Bonjour Service

# Disable
sudo defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ProgramArguments -array-add "-NoMulticastAdvertisements"

# Enable (Default)
sudo defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ProgramArguments -array "/usr/sbin/mDNSResponder" "-launchd"

DHCP

Renew DHCP Lease

sudo ipconfig set en0 DHCP

Show DHCP Info

ipconfig getpacket en0

DNS

Clear DNS Cache

sudo dscacheutil -flushcache && \
sudo killall -HUP mDNSResponder

Hostname

Set Computer Name/Host Name

sudo scutil --set ComputerName "newhostname" && \
sudo scutil --set HostName "newhostname" && \
sudo scutil --set LocalHostName "newhostname" && \
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "newhostname"

Network Preferences

Network Locations

Switch between network locations created in the Network preference pane.

# Status
scselect

# Switch Network Location
scselect LocationNameFromStatus

Set Static IP Address

networksetup -setmanual "Ethernet" 192.168.2.100 255.255.255.0 192.168.2.1

Networking Tools

Ping a Host to See Whether It’s Available

ping -o github.com

Troubleshoot Routing Problems

traceroute github.com

SSH

Permanently Add Private Key Passphrase to SSH Agent

Prior to macOS 10.12 (Sierra), ssh would present a dialog asking for your passphrase and would offer the option to store it into the keychain. This UI was deprecated some time ago and has been removed.

Instead, a new UseKeychain option was introduced in macOS 10.12 (Sierra) allowing users to specify whether they would like for the passphrase to be stored in the keychain. This option was enabled by default on macOS 10.12 (Sierra), which caused all passphrases to be stored in the keychain.

This was not the intended default behavior, so this has been changed in macOS 10.12.2. (Source)

ssh-add -K /path/to/private_key

Then add to ~/.ssh/config:

Host server.example.com
    IdentityFile /path/to/private_key
    UseKeychain yes

Remote Login

# Enable
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

# Disable (Default)
sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist

TCP/IP

Show Application Using a Certain Port

This outputs all applications currently using port 80.

sudo lsof -i :80

Show External IP Address

Works if your ISP doesn't replace DNS requests (which it shouldn't).

dig +short myip.opendns.com @resolver1.opendns.com

Alternative that works on all networks.

curl -s https://api.ipify.org && echo

Show Network Interface Information

Undocumented flag of the scutil command.

scutil --nwi

TFTP

Start Native TFTP Daemon

Files will be served from /private/tftpboot.

sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist && \
sudo launchctl start com.apple.tftpd

Wi-Fi

Join a Wi-Fi Network

networksetup -setairportnetwork en0 WIFI_SSID WIFI_PASSWORD

Scan Available Access Points

Create a symbolic link to the airport command for easy access:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport

Run a wireless scan:

airport -s

Show Current SSID

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'

Show Local IP Address

ipconfig getifaddr en0

Show Wi-Fi Connection History

defaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences | grep LastConnected -A 7

Show Wi-Fi Network Passwords

Exchange SSID with the SSID of the access point you wish to query the password from.

security find-generic-password -D "AirPort network password" -a "SSID" -gw

Turn on Wi-Fi Adapter

networksetup -setairportpower en0 on

Package Managers

  • Fink - The full world of Unix Open Source software for Darwin. A little outdated.
  • Homebrew - The missing package manager for OS X. The most popular choice.
  • MacPorts - Compile, install and upgrade either command-line, X11 or Aqua based open-source software.

Homebrew

Full Uninstall

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Printing

Clear Print Queue

cancel -a -

Expand Print Panel by Default

defaults write -g PMPrintingExpandedStateForPrint -bool true && \
defaults write -g PMPrintingExpandedStateForPrint2 -bool true

Quit Printer App After Print Jobs Complete

defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true

Security

Application Firewall

Firewall Service

# Show Status
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate

# Enable
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on

# Disable (Default)
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off

Add Application to Firewall

sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /path/to/file

Gatekeeper

Add Gatekeeper Exception

spctl --add /path/to/Application.app

Remove Gatekeeper Exception

spctl --remove /path/to/Application.app

Manage Gatekeeper

Especially helpful with the annoying macOS 10.15 (Catalina) system popup blocking execution of non-signed apps.

# Status
spctl --status

# Enable (Default)
sudo spctl --master-enable

# Disable
sudo spctl --master-disable

Passwords

Generate Secure Password and Copy to Clipboard

LC_ALL=C tr -dc "[:alnum:]" < /dev/urandom | head -c 20 | pbcopy

Physical Access

Launch Screen Saver

# Up to macOS 10.12 (Sierra)
open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app

# From macOS 10.13 (High Sierra)
/System/Library/CoreServices/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine

Lock Screen

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend

Screensaver Immediate Lock

# Status
defaults read com.apple.screensaver askForPasswordDelay

# Enable (Default)
defaults write com.apple.screensaver askForPasswordDelay -int 0

# Disable (Integer = lock delay in seconds)
defaults write com.apple.screensaver askForPasswordDelay -int 10

Screensaver Password

# Status
defaults read com.apple.screensaver askForPassword

# Enable
defaults write com.apple.screensaver askForPassword -int 1

# Disable (Default)
defaults write com.apple.screensaver askForPassword -int 0

Privacy Database

The tccutil command manages the privacy database, which stores decisions the user has made about whether apps may access personal data. You need to close all applications except Terminal before running any of these commands.

# Full Reset for All Applications
sudo tccutil reset All

# Reset Adress Book Access
sudo tccutil reset AddressBook

# Reset All Permission for Terminal.app
sudo tccutil reset All com.apple.Terminal

Wiping Data

Note: The srm command appears to have been removed on MacOS after 10.9. There is a note on an Apple support page hinting as to why:

With an SSD drive, Secure Erase and Erasing Free Space are not available in Disk Utility. These options are not needed for an SSD drive because a standard erase makes it difficult to recover data from an SSD.

Securely Remove File

srm /path/to/file

Securely Remove Folder

srm -r /path/to/folder/

Securely Remove Path (Force)

srm -rf /path/to/complete/destruction

Search

Find

Recursively Delete .DS_Store Files

find . -type f -name '*.DS_Store' -ls -delete

Locate

Build Locate Database

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

Search via Locate

The -i modifier makes the search case insensitive.

locate -i *.jpg

System

AirDrop

AirDrop over Ethernet on Unsupported Macs

# Enable 
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true && \
defaults remove com.apple.NetworkBrowser DisableAirDrop

# Disable (Default)
defaults delete com.apple.NetworkBrowser BrowseAllInterfaces && \
defaults write com.apple.NetworkBrowser DisableAirDrop -bool YES

AppleScript

Execute AppleScript

osascript /path/to/script.scpt

Basics

Compare Two Folders

diff -qr /path/to/folder1 /path/to/folder2

Copy Large File with Progress

Make sure you have pv installed and replace /dev/rdisk2 with the appropriate write device or file.

FILE=/path/to/file.iso pv -s $(du -h $FILE | awk '/.*/ {print $1}') $FILE | sudo dd of=/dev/rdisk2 bs=1m

Restore Sane Shell

In case your shell session went insane (some script or application turned it into a garbled mess).

stty sane

Restart

sudo reboot

Shutdown

sudo poweroff

Show Build Number of OS

sw_vers

Uptime

How long since your last restart.

uptime

Clipboard

Copy data to Clipboard

cat whatever.txt | pbcopy

Convert Clipboard to Plain Text

pbpaste | textutil -convert txt -stdin -stdout -encoding 30 | pbcopy

Convert Tabs to Spaces for Clipboard Content

pbpaste | expand | pbcopy

Copy data from Clipboard

pbpaste > whatever.txt

Sort and Strip Duplicate Lines from Clipboard Content

pbpaste | sort | uniq | pbcopy

FileVault

Automatically Unlock FileVault on Restart

If FileVault is enabled on the current volume, it restarts the system, bypassing the initial unlock. The command may not work on all systems.

sudo fdesetup authrestart

FileVault Service

# Status
sudo fdesetup status

# Enable
sudo fdesetup enable

# Disable (Default)
sudo fdesetup disable

Information/Reports

Generate Advanced System and Performance Report

sudo sysdiagnose -f ~/Desktop/

Installation

Create Bootable Installer

# macOS 10.15 (Catalina)
sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --nointeraction --downloadassets

# macOS 10.14 (Mojave)
sudo /Applications/Install\ macOS\ Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --nointeraction --downloadassets

# macOS 10.13 (High Sierra)
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install\ macOS\ High\ Sierra.app

# macOS 10.12 (Sierra)
sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install\ macOS\ Sierra.app

# OS X 10.11 (El Capitan)
sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app

# OS X 10.10 (Yosemite)
sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/USB --applicationpath /Applications/Install\ OS\ X\ Yosemite.app
  • For confirmation before erasing the drive, remove –-nointeraction from the command.
  • The optional –-downloadassets flag is new in macOS 10.14 (Mojave). It downloads assets which may be required during installation, like updates.
  • The –-applicationpath flag is deprecated since macOS 10.14 (Mojave) and will throw an error if used.

Download Older OS Versions

Version Codename Download
Mac OS X 10.0 Cheetah n/a
Mac OS X 10.1 Puma n/a
Mac OS X 10.2 Jaguar n/a
Mac OS X 10.3 Panther n/a
Mac OS X 10.4 Tiger n/a
Mac OS X 10.5 Leopard n/a
Mac OS X 10.6 Snow Leopard n/a
Mac OS X 10.7 Lion n/a
OS X 10.8 Mountain Lion n/a
OS X 10.9 Mavericks n/a
OS X 10.10 Yosemite Direct Download
OS X 10.11 El Capitan Direct Download
macOS 10.12 Sierra Direct Download
macOS 10.13 High Sierra App Store
macOS 10.14 Mojave App Store
macOS 10.15 Catalina App Store

Kernel Extensions

Display Status of Loaded Kernel Extensions

sudo kextstat -l

Load Kernel Extension

sudo kextload -b com.apple.driver.ExampleBundle

Unload Kernel Extensions

sudo kextunload -b com.apple.driver.ExampleBundle

LaunchAgents

Please see this file.

LaunchServices

Rebuild LaunchServices Database

To be independent of OS X version, this relies on locate to find lsregister. If you do not have your locate database built yet, do it.

sudo $(locate lsregister) -kill -seed -r

Login Window

Set Login Window Text

sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Your text"

Memory Management

Purge memory cache

sudo purge

Show Memory Statistics

# One time
vm_stat

# Table of data, repeat 10 times total, 1 second wait between each poll
vm_stat -c 10 1

Notification Center

Notification Center Service

# Disable
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist && \
killall -9 NotificationCenter

# Enable (Default)
launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist

QuickLook

Preview via QuickLook

qlmanage -p /path/to/file

Remote Management

See also: Apple Remote Desktop.

Prevent Double Password Entry

When logging into a Mac remotely via Apple Remote Desktop or VNC, you are sometimes required to enter your password a second time after connecting to the Mac. While you can disable this behavior, it is explicitly not recommend to turn this functionality off unless you are certain that no one else will be able to access your Mac physically when you are away.

# Disable
sudo defaults write /Library/Preferences/com.apple.RemoteManagement.plist RestoreMachineState -bool no

# Enable (Default)
sudo defaults write /Library/Preferences/com.apple.RemoteManagement.plist RestoreMachineState -bool yes

Remote Apple Events

# Status
sudo systemsetup -getremoteappleevents

# Enable
sudo systemsetup -setremoteappleevents on

# Disable (Default)
sudo systemsetup -setremoteappleevents off

Root User

# Enable
dsenableroot

# Disable (Default)
dsenableroot -d

Safe Mode Boot

# Status
nvram boot-args

# Enable
sudo nvram boot-args="-x"

# Disable (Default)
sudo nvram boot-args=""

Save Dialogs

Significantly improve the now rather slow animation in save dialogs.

defaults write NSGlobalDomain NSWindowResizeTime .001

Screenshots

Take Delayed Screenshot

Takes a screenshot as JPEG after 3 seconds and displays in Preview.

screencapture -T 3 -t jpg -P delayedpic.jpg

Save Screenshots to Given Location

Sets location to ~/Desktop.

defaults write com.apple.screencapture location ~/Desktop && \
killall SystemUIServer

Save Screenshots in Given Format

Sets format to png. Other options are bmp, gif, jpg, jpeg, pdf, tiff.

defaults write com.apple.screencapture type -string "png"

Disable Shadow in Screenshots

defaults write com.apple.screencapture disable-shadow -bool true && \
killall SystemUIServer

Set Default Screenshot Name

Date and time remain unchanged.

defaults write com.apple.screencapture name "Example name" && \
killall SystemUIServer

Software Installation

Install PKG

installer -pkg /path/to/installer.pkg -target /

Sidecar

Use on Incompatible Macs

This may or may not work, depending on the age of the machine.

# Enable
defaults write com.apple.sidecar.display AllowAllDevices -bool true && \
defaults write com.apple.sidecar.display hasShownPref -bool true

# Disable (Default)
defaults delete com.apple.sidecar.display

Software Update

Ignore Specific Software Update

The identifier can be found via softwareupdate --list. In the example below, being on macOS 10.14 (Mojave), will ignore all update prompts to macOS 10.15 (Catalina), since the latter removes 32-bit support.

sudo /usr/sbin/softwareupdate --ignore "macOS Catalina"

Install All Available Software Updates

sudo softwareupdate -ia

Set Software Update Check Interval

Set to check daily instead of weekly.

defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1

Show Available Software Updates

sudo softwareupdate --list

Set Software Update Server

This should only be done for testing purposes or unmanaged clients. To use network-wide, either correctly set up DNS along with Apple SUS service and bind your clients via OpenDirectory. Alternatively, use Reposado together with correct network DNS settings to make resolution transparent. Margarita looks nice to have as well.

# Use own SUS
sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://su.example.com:8088/index.sucatalog

# Reset to Apple SUS
sudo defaults delete /Library/Preferences/com.apple.SoftwareUpdate CatalogURL

Software Version

Show System Software Version

sw_vers -productVersion

Spotlight

Spotlight Indexing

# Disable
mdutil -i off -d /path/to/volume

# Enable (Default)
mdutil -i on /path/to/volume

Erase Spotlight Index and Rebuild

mdutil -E /path/to/volume

Search via Spotlight

mdfind -name 'searchterm'

Show Spotlight Indexed Metadata

mdls /path/to/file

System Integrity Protection

Reboot while holding Cmd + R and open the Terminal application. You will need to reboot for the commands to take effect.

# Status
csrutil status

# Enable (Default)
csrutil enable

# Disable
csrutil disable

Date and Time

List Available Timezones

sudo systemsetup -listtimezones

Set Timezone

sudo systemsetup -settimezone Europe/Berlin

Set Clock Using Network Time

# Status
sudo systemsetup getusingnetworktime

# Enable (Default)
sudo systemsetup setusingnetworktime on

# Disable
sudo systemsetup setusingnetworktime off

Set Menu Bar Clock Output Format

# System Preferences > Date & Time > Time options
# Analogue
sudo defaults write com.apple.menuextra.clock IsAnalog -bool true
# Digital (Default)
sudo defaults write com.apple.menuextra.clock IsAnalog -bool false

# System Preferences > Date & Time > Flash the time separators
# Enable
sudo defaults write com.apple.menuextra.clock FlashDateSeparators -bool true
# Disable (Default)
sudo defaults write com.apple.menuextra.clock FlashDateSeparators -bool false

# Thu 18 Aug 23:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM HH:mm:ss"

# Thu 23:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE HH:mm:ss"

# 18 Aug 23:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "d MMM HH:mm:ss"

# 23:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "HH:mm:ss"

# Thu 18 Aug 11:46:18 pm
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM h:mm:ss a"


# Thu 11:46:18 pm
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE h:mm:ss a"

# 18 Aug 11:46:18 pm
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "d MMM h:mm:ss a"

# 11:46:18 pm
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "h:mm:ss a"

# Thu 18 Aug 11:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM h:mm:ss"

# Thu 11:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE h:mm:ss"

# 18 Aug 11:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "d MMM h:mm:ss"

# 11:46:18
# System Preferences > Date & Time > Display time with seconds - Checked [:ss]
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "h:mm:ss"

# Thu 18 Aug 23:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM HH:mm"

# Thu 23:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE HH:mm"

# 18 Aug 23:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "d MMM HH:mm"

# 23:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Checked [HH:mm]
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "HH:mm"

# Thu 18 Aug 11:46 pm
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM h:mm a"

# Thu 11:46 pm
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE h:mm a"

# 18 Aug 11:46 pm
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "d MMM h:mm a"

# 11:46 pm
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Checked [a]
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "h:mm a"

# Thu 18 Aug 11:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM h:mm"

# Thu 11:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Checked [EEE]
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "EEE h:mm"

# 18 Aug 11:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Checked [d MMM]
sudo defaults write com.apple.menuextra.clock DateFormat -string "d MMM h:mm"

# 11:46
# System Preferences > Date & Time > Display time with seconds - Unchecked
# System Preferences > Date & Time > Use a 24-hour clock - Unchecked
# System Preferences > Date & Time > Show AM/PM - Unchecked
# System Preferences > Date & Time > Show the day of the week - Unchecked
# System Preferences > Date & Time > Show date - Unchecked
sudo defaults write com.apple.menuextra.clock DateFormat -string "h:mm"

# Apply changes immediately
sudo killall SystemUIServer

(Source)

Terminal

Ring Terminal Bell

Rings the terminal bell (if enabled) and puts a badge on it.

tput bel

Alternative Terminals

  • Alacritty - Cross-platform, GPU-accelerated terminal emulator.
  • iTerm2 - A better Terminal.app.
  • kitty - Modern, GPU-accelerated terminal emulator.

Shells

Bash

Install the latest version and set as current user's default shell:

brew install bash && \
echo $(brew --prefix)/bin/bash | sudo tee -a /etc/shells && \
chsh -s $(brew --prefix)/bin/bash
  • Homepage - The default shell for OS X and most other Unix-based operating systems.
  • Bash-it - Community Bash framework, like Oh My Zsh for Bash.

fish

Install the latest version and set as current user's default shell:

brew install fish && \
echo $(brew --prefix)/bin/fish | sudo tee -a /etc/shells && \
chsh -s $(brew --prefix)/bin/fish
  • Homepage - A smart and user-friendly command line shell for OS X, Linux, and the rest of the family.
  • The Fishshell Framework - Provides core infrastructure to allow you to install packages which extend or modify the look of your shell.
  • Installation & Configuration Tutorial - How to Setup Fish Shell with Fisherman, Powerline Fonts, iTerm2 and Budspencer Theme on OS X.

Zsh

Install the latest version and set as current user's default shell:

brew install zsh && \
sudo sh -c 'echo $(brew --prefix)/bin/zsh >> /etc/shells' && \
chsh -s $(brew --prefix)/bin/zsh
  • Homepage - Zsh is a shell designed for interactive use, although it is also a powerful scripting language.
  • Oh My Zsh - An open source, community-driven framework for managing your Zsh configuration.
  • Prezto - A speedy Zsh framework. Enriches the command line interface environment with sane defaults, aliases, functions, auto completion, and prompt themes.
  • zgen - Another open source framework for managing your zsh configuration. Zgen will load oh-my-zsh compatible plugins and themes and has the advantage of both being faster and automatically cloning any plugins used in your configuration for you.

Terminal Fonts

  • Anonymous Pro - A family of four fixed-width fonts designed with coding in mind.
  • Codeface - A gallery and repository of monospaced fonts for developers.
  • DejaVu Sans Mono - A font family based on the Vera Fonts.
  • Fantasque Sans Mono - Designed with functionality in mind, and with some wibbly-wobbly handwriting-like fuzziness that makes it unassumingly cool.
  • Hack - Hack is hand groomed and optically balanced to be your go-to code face.
  • Inconsolata - A monospace font, designed for code listings and the like.
  • Input - A flexible system of fonts designed specifically for code.
  • Meslo - Customized version of Apple's Menlo font.
  • Operator Mono - A surprisingly usable alternative take on a monospace font (commercial).
  • Powerline Fonts - Repo of patched fonts for the Powerline plugin.
  • Source Code Pro - A monospaced font family for user interfaces and coding environments.

Glossary

Mac OS X, OS X, and macOS Version Information

Version Codename Release Date Most Recent Version
Rhapsody Developer Release Grail1Z4 / Titan1U August 31, 1997 DR2 (May 14, 1998)
Mac OS X Server 1.0 Hera March 16, 1999 1.2v3 (October 27, 2000)
Mac OS X Developer Preview n/a March 16, 1999 DP4 (April 5, 2000)
Mac OS X Public Beta Kodiak September 13, 2000 n/a
Mac OS X 10.0 Cheetah March 24, 2001 10.0.4 (June 22, 2001)
Mac OS X 10.1 Puma September 25, 2001 10.1.5 (June 6, 2002)
Mac OS X 10.2 Jaguar August 24, 2002 10.2.8 (October 3, 2003)
Mac OS X 10.3 Panther October 24, 2003 10.3.9 (April 15, 2005)
Mac OS X 10.4 Tiger April 29, 2005 10.4.11 (November 14, 2007)
Mac OS X 10.5 Leopard October 26, 2007 10.5.8 (August 5, 2009)
Mac OS X 10.6 Snow Leopard August 28, 2009 10.6.8 v1.1 (July 25, 2011)
Mac OS X 10.7 Lion July 20, 2011 10.7.5 (September 19, 2012)
OS X 10.8 Mountain Lion July 25, 2012 10.8.5 (12F45) (October 3, 2013)
OS X 10.9 Mavericks October 22, 2013 10.9.5 (13F1112) (September 18, 2014)
OS X 10.10 Yosemite October 16, 2014 10.10.5 (14F27) (August 13, 2015)
OS X 10.11 El Capitan September 30, 2015 10.11.6 (15G31) (July 18, 2016)
macOS 10.12 Sierra September 20, 2016 10.12.6 (16G29) (July 19, 2017)
macOS 10.13 High Sierra September 25, 2017 10.13.6 (17G65) (July 9, 2018)
macOS 10.14 Mojave September 24, 2018 10.14.6 (18G3020) (January 28, 2020)
macOS 10.15 Catalina October 7, 2019 10.15.5 (19F101) (June 1, 2020)

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.