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)
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.
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.
- Appearance
- Applications
- Backup
- Developer
- Dock
- Documents
- Files, Disks and Volumes
- Finder
- Fonts
- Functions
- Hardware
- Input Devices
- Launchpad
- Media
- Networking
- Package Managers
- Printing
- Security
- Search
- System
- AirDrop
- AppleScript
- Basics
- Clipboard
- Date and Time
- FileVault
- Information/Reports
- Install OS
- Kernel Extensions
- LaunchAgents
- LaunchServices
- Login Window
- Memory Management
- Notification Center
- QuickLook
- Remote Apple Events
- Root User
- Safe Mode Boot
- Save Dialogs
- Screenshots
- Software Installation
- Software Update
- Software Version
- Spotlight
- System Integrity Protection
- Terminal
- Glossary
# Reduce Transparency
defaults write com.apple.universalaccess reduceTransparency -bool true
# Restore Default Transparency
defaults write com.apple.universalaccess reduceTransparency -bool false
# Up to Mountain Lion
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/path/to/picture.jpg"'
# Since Mavericks
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "update data set value = '/path/to/picture.jpg'" && killall Dock
# Via find
find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |\sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'
# Via Spotlight
mdfind kMDItemAppStoreHasReceipt=1
Works up to Yosemite.
# Enable
defaults write com.apple.appstore ShowDebugMenu -bool true
# Disable (Default)
defaults write com.apple.appstore ShowDebugMenu -bool false
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -help
# Activate And Restart the ARD Agent and Helper
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -restart -agent -console
# Deactivate and Stop the Remote Management Service
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -stop
# Allow Access for All Users and Give All Users Full Access
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all
# Disable ARD Agent and Remove Access Privileges for All Users
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -configure -access -off
sudo rm -rf /var/db/RemoteManagement ; \
sudo defaults delete /Library/Preferences/com.apple.RemoteDesktop.plist ; \
defaults delete ~/Library/Preferences/com.apple.RemoteDesktop.plist ; \
sudo rm -r /Library/Application\ Support/Apple/Remote\ Desktop/ ; \
rm -r ~/Library/Application\ Support/Remote\ Desktop/ ; \
rm -r ~/Library/Containers/com.apple.RemoteDesktop
# Enable
defaults write com.apple.addressbook ABShowDebugMenu -bool true
# Disable (Default)
defaults write com.apple.addressbook ABShowDebugMenu -bool false
~/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/ksinstall --nuke
This works up to Yosemite. System Integrity Protection was introduced in El Capitan which prevents system Launch Agents from being unloaded.
# Stop Responding to Key Presses
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist
# Respond to Key Presses (Default)
launchctl load -w /System/Library/LaunchAgents/com.apple.rcd.plist
From El Capitan onwards, you can either disable SIP or resort to a kind of hack, which will make iTunes inaccessible to any user, effectively preventing it from starting itself or its helpers. Be aware that for all intents and purposes this will trash your iTunes installation and may conflict with OS updates down the road.
sudo chmod 0000 /Applications/iTunes.app
defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes
The AppleScript code below will quit Mail, vacuum the SQLite index, then re-open Mail. On a large email database that hasn't been optimized for a while, this can provide significant improvements in responsiveness and speed.
(*
Speed up Mail.app by vacuuming the Envelope Index
Code from: http://web.archive.org/web/20071008123746/http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick/
Originally by "pmbuko" with modifications by Romulo
Updated by Brett Terpstra 2012
Updated by Mathias Törnblom 2015 to support V3 in El Capitan and still keep backwards compatibility
Updated by Andrei Miclaus 2017 to support V4 in Sierra
*)
tell application "Mail" to quit
set os_version to do shell script "sw_vers -productVersion"
set mail_version to "V2"
considering numeric strings
if "10.10" <= os_version then set mail_version to "V3"
if "10.12" <= os_version then set mail_version to "V4"
if "10.13" <= os_version then set mail_version to "V5"
if "10.14" <= os_version then set mail_version to "V6"
end considering
set sizeBefore to do shell script "ls -lnah ~/Library/Mail/" & mail_version & "/MailData | grep -E 'Envelope Index$' | awk {'print $5'}"
do shell script "/usr/bin/sqlite3 ~/Library/Mail/" & mail_version & "/MailData/Envelope\\ Index vacuum"
set sizeAfter to do shell script "ls -lnah ~/Library/Mail/" & mail_version & "/MailData | grep -E 'Envelope Index$' | awk {'print $5'}"
display dialog ("Mail index before: " & sizeBefore & return & "Mail index after: " & sizeAfter & return & return & "Enjoy the new speed!")
tell application "Mail" to activate
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2StandardFontFamily Georgia
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFontSize 16
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2FixedFontFamily Menlo
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFixedFontSize 14
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
Other options: get source
, get text
.
osascript -e 'tell application "Safari" to get URL of current tab of front window'
# Enable
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool YES
# Disable
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool NO
defaults write com.bohemiancoding.sketch3 exportCompactSVG -bool yes
Removes the dialog and defaults to auto reload.
defaults write -app Skim SKAutoReloadFileUpdate -boolean true
# Enable
defaults write com.apple.Terminal FocusFollowsMouse -string YES
# Disable
defaults write com.apple.Terminal FocusFollowsMouse -string NO
defaults write com.apple.TextEdit RichText -int 0
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
This changes the interval to 30 minutes. The integer value is the time in seconds.
sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 1800
Whether Time Machine performs local backups while the Time Machine backup volume is not available.
# Status
defaults read /Library/Preferences/com.apple.TimeMachine MobileBackups
# Enable (Default)
sudo tmutil enablelocal
# Disable
sudo tmutil disablelocal
Since High Sierra, you cannot disable local snapshots. Time Machine now always creates a local APFS snapshot and uses that snapshot as the data source to create a regular backup, rather than using the live disk as the source, as is the case with HFS formatted disks.
sudo defaults write /Library/Preferences/com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
This little script will output the last 12 hours of Time Machine activity followed by live activity.
#!/bin/sh
filter='processImagePath contains "backupd" and subsystem beginswith "com.apple.TimeMachine"'
# show the last 12 hours
start="$(date -j -v-12H +'%Y-%m-%d %H:%M:%S')"
echo ""
echo "[History (from $start)]"
echo ""
log show --style syslog --info --start "$start" --predicate "$filter"
echo ""
echo "[Following]"
echo ""
log stream --style syslog --info --predicate "$filter"
# Status
sudo defaults read /Library/Preferences/com.apple.TimeMachine RequiresACPower
# Enable (Default)
sudo defaults write /Library/Preferences/com.apple.TimeMachine RequiresACPower -bool true
# Disable
sudo defaults write /Library/Preferences/com.apple.TimeMachine RequiresACPower -bool false
Beginning in OS X 10.11, Time Machine records checksums of files copied into snapshots. Checksums are not retroactively computed for files that were copied by earlier releases of OS X.
sudo tmutil verifychecksums /path/to/backup
Compiling MacVim via Homebrew with all bells and whistles, including overriding system Vim.
brew install macvim --HEAD
Install the modern Vim drop-in alternative via Homebrew.
brew install neovim
xcode-select --install
xcrun simctl delete unavailable
defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }' && \
killall Dock
defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = {}; "tile-type"="small-spacer-tile"; }' && \
killall Dock
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' && \
killall Dock
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}' && \
killall Dock
# Enable (Default)
defaults write com.apple.dock mru-spaces -bool true && \
killall Dock
# Disable
defaults write com.apple.dock mru-spaces -bool false && \
killall Dock
# Enable
defaults write com.apple.dock autohide -bool true && \
killall Dock
# Disable (Default)
defaults write com.apple.dock autohide -bool false && \
killall Dock
Global setting whether Dock icons should bounce when the respective application demands your attention.
# Enable (Default)
defaults write com.apple.dock no-bouncing -bool true && \
killall Dock
# Disable
defaults write com.apple.dock no-bouncing -bool false && \
killall Dock
# Enable
defaults write com.apple.Dock size-immutable -bool yes && \
killall Dock
# Disable (Default)
defaults write com.apple.Dock size-immutable -bool no && \
killall Dock
defaults delete com.apple.dock && \
killall Dock
Fully resize your Dock's body. To resize change the 0
value as an integer.
defaults write com.apple.dock tilesize -int 0 && \
killall Dock
Use your touchpad or mouse scroll wheel to interact with Dock items. Allows you to use an upward scrolling gesture to open stacks. Using the same gesture on applications that are running invokes Exposé/Mission Control.
# Enable
defaults write com.apple.dock scroll-to-open -bool true && \
killall Dock
# Disable (Default)
defaults write com.apple.dock scroll-to-open -bool false && \
killall Dock
The float number defines the show/hide delay in ms.
defaults write com.apple.dock autohide-time-modifier -float 0.4 && \
defaults write com.apple.dock autohide-delay -float 0 && \
killall Dock
Show Hidden App Icons
# Enable
defaults write com.apple.dock showhidden -bool true && \
killall Dock
# Disable (Default)
defaults write com.apple.dock showhidden -bool false && \
killall Dock
# Enable
defaults write com.apple.dock static-only -bool true && \
killall Dock
# Disable (Default)
defaults write com.apple.dock static-only -bool false && \
killall Dock
When clicking an application icon in the Dock, the respective windows will come to the front, but all other application windows will be hidden.
# Enable
defaults write com.apple.dock single-app -bool true && \
killall Dock
# Disable (Default)
defaults write com.apple.dock single-app -bool false && \
killall Dock
Supported formats are plain text, rich text (rtf) and Microsoft Word (doc/docx).
textutil -convert html file.ext
Creates an empty 10 gigabyte test file.
mkfile 10g /path/to/file
Leaving this turned on is useless when you're using SSDs.
sudo pmset -a sms 0
The only reliable way to do this is by sending an AppleScript command to Finder.
osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
You don't have to use the Disk Utility GUI for this.
sudo diskutil repairPermissions /
Beginning with OS X El Capitan, system file permissions are automatically protected. It's no longer necessary to verify or repair permissions with Disk Utility. (Source)
# Up to Yosemite
bless --mount "/path/to/mounted/volume" --setBoot
# From El Capitan
sudo systemsetup -setstartupdisk /System/Library/CoreServices
diskutil list
A continuous stream of file system access info.
sudo fs_usage
Available since High Sierra. There is no central utility and usage is inconsistent as most functionality is rolled into tmutil
.
/System/Library/Filesystems/apfs.fs/Contents/Resources/hfs_convert /path/to/file/system
/System/Library/Filesystems/apfs.fs/Contents/Resources/newfs_apfs /path/to/device
tmutil localsnapshot
tmutil deletelocalsnapshots com.apple.TimeMachine.2018-01-26-044042
tmutil listlocalsnapshots /
Snapshots are read-only.
mkdir ~/mnt
/System/Library/Filesystems/apfs.fs/Contents/Resources/mount_apfs -s com.apple.TimeMachine.2018-01-26-044042 / ~/mnt
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
This command applies to .iso, .img and .dmg images.
hdiutil burn /path/to/image_file
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
bless --folder "/path/to/mounted/volume/System/Library/CoreServices" --bootinfo --bootefi
hdiutil attach /path/to/diskimage.dmg
hdiutil detach /dev/disk2s1
Like the Disk Utility "Restore" function.
sudo asr -restore -noverify -source /path/to/diskimage.dmg -target /Volumes/VolumeToRestoreTo
External HDs, thumb drives, etc.
# Enable
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true && \
killall Finder
# Disable (Default)
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool false && \
killall Finder
Built-in HDs or SSDs.
# Enable
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true && \
killall Finder
# Disable (Default)
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false && \
killall Finder
CDs, DVDs, iPods, etc.
# Enable
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true && \
killall Finder
# Disable (Default)
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false && \
killall Finder
AFP, SMB, NFS, WebDAV, etc.
# Enable
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true && \
killall Finder
# Disable (Default)
defaults write com.apple.finder ShowMountedServersOnDesktop -bool false && \
killall Finder
sudo chmod -RN /path/to/folder
chflags hidden /path/to/folder/
defaults write -g AppleShowAllExtensions -bool true
Show Hidden Files
# Show All
defaults write com.apple.finder AppleShowAllFiles true
# Restore Default File Visibility
defaults write com.apple.finder AppleShowAllFiles false
sudo chflags -R nouchg /path/to/file/or/folder
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
chflags nohidden ~/Library
defaults write -g NSNavRecentPlacesLimit -int 10 && \
killall Finder
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
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
# Disable
defaults write -g NSScrollViewRubberbanding -bool false
# Enable (Default)
defaults write -g NSScrollViewRubberbanding -bool true
defaults write -g NSNavPanelExpandedStateForSaveMode -bool true && \
defaults write -g NSNavPanelExpandedStateForSaveMode2 -bool true
# 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
# Show
defaults write com.apple.finder ShowPathbar -bool true
# Hide (Default)
defaults write com.apple.finder ShowPathbar -bool false
Possible values: WhenScrolling
, Automatic
and Always
.
defaults write -g AppleShowScrollBars -string "Always"
# Show
defaults write com.apple.finder ShowStatusBar -bool true
# Hide (Default)
defaults write com.apple.finder ShowStatusBar -bool false
Sets default save target to be a local disk, not iCloud.
defaults write -g NSDocumentSaveNewDocumentsToCloud -bool false
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
defaults write com.apple.finder NewWindowTarget -string "PfLo" && \
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}"
Sets size to 'medium'.
defaults write -g NSTableViewDefaultSizeMode -int 2
Avoids creation of .DS_Store
and AppleDouble files.
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
Avoids creation of .DS_Store
and AppleDouble files.
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
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 https://github.com