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.
- Appearance
- Applications
- Backup
- Developer
- Disks and Volumes
- Documents
- Finder
- Fonts
- Hardware
- Input Devices
- Media
- Networking
- Package Managers
- Printing
- Security
- Search
- System
- Terminal
defaults write com.apple.universalaccess reduceTransparency -bool truedefaults write com.apple.universalaccess reduceTransparency -bool falseosascript -e 'tell application "Finder" to set desktop picture to POSIX file "/path/to/picture.jpg"'find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |\sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'sudo rm -rf /var/db/RemoteManagement && \
sudo rm /Library/Preferences/com.apple.RemoteDesktop.plist && \
rm ~/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.RemoteDesktopdefaults 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 NSGlobalDomain WebKitDeveloperExtras -bool truedefaults write com.bohemiancoding.sketch3 exportCompactSVG -bool yesdefaults write com.apple.TextEdit RichText -int 0This changes the interval to 30 minutes. The integer value is the time in seconds.
sudo defaults write /System/Library/Launch Daemons/com.apple.backupd-auto StartInterval -int 1800hash tmutil &> /dev/null && sudo tmutil disablelocaldefaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool trueFunction to quickly create an application icon from 1024px master file.
function mkicns() {
if [[ -z "$@" ]]; then
echo "Input file missing"
else
filename=${1%.*}
mkdir $filename.iconset
sips -z 16 16 $1 --out $filename.iconset/icon_16x16.png
sips -z 32 32 $1 --out $filename.iconset/[email protected]
sips -z 32 32 $1 --out $filename.iconset/icon_32x32.png
sips -z 64 64 $1 --out $filename.iconset/[email protected]
sips -z 128 128 $1 --out $filename.iconset/icon_128x128.png
sips -z 256 256 $1 --out $filename.iconset/[email protected]
sips -z 256 256 $1 --out $filename.iconset/icon_256x256.png
sips -z 512 512 $1 --out $filename.iconset/[email protected]
sips -z 512 512 $1 --out $filename.iconset/icon_512x512.png
cp $1 $filename.iconset/[email protected]
iconutil -c icns $filename.iconset
rm -r $filename.iconset
fi
}Compiling MacVim via Homebrew with all bells and whistles, including overriding system Vim.
brew install macvim --HEAD --with-cscope --with-lua --with-override-system-vim --with-luajit --with-pythonInstall the development version of this modern Vim drop-in alternative via Homebrew.
brew tap neovim/neovim && \
brew install --HEAD neovimxcode-select --installxcrun simctl delete unavailableLeaving this turned on is useless when you're using SSDs.
sudo pmset -a sms 0The 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)
bless --mount "/path/to/mounted/volume" --setBootdiskutil listA contiuous stream of file system access info.
sudo fs_usagedefaults 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 truebless --folder "/path/to/mounted/volume/System/Library/CoreServices" --bootinfo --bootefihdiutil attach /path/to/diskimage.dmghdiutil detach /dev/disk2s1Like the Disk Utility "Restore" function.
sudo asr -restore -noverify -source /path/to/diskimage.dmg -target /Volumes/VolumeToRestoreToSupported formats are plain text, rich text (rtf) and Microsoft Word (doc/docx).
textutil -convert html file.extchflags hidden /path/to/folder/defaults write NSGlobalDomain AppleShowAllExtensions -bool trueShow All Hidden Files
defaults write com.apple.finder AppleShowAllFiles truedefaults write com.apple.finder AppleShowAllFiles falsedefaults write com.apple.finder _FXShowPosixPathInTitle -bool truechflags nohidden ~/LibraryUseful if you’re on an older Mac that messes up the animation.
defaults write NSGlobalDomain NSScrollAnimationEnabled -bool falseRevert back to standard behavior.
defaults write NSGlobalDomain NSScrollAnimationEnabled -bool truedefaults write -g NSScrollViewRubberbanding -bool falseRevert to default behavior.
defaults write -g NSScrollViewRubberbanding -bool truedefaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true && \
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool truedefaults write com.apple.finder CreateDesktop -bool false && killall Finderdefaults write com.apple.finder CreateDesktop -bool true && killall Finderdefaults write com.apple.finder ShowPathbar -bool truePossible values: WhenScrolling, Automatic and Always.
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"defaults write com.apple.finder ShowStatusBar -bool trueSets default save target to be a local disk, not iCloud.
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool falsedefaults 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 NSGlobalDomain NSTableViewDefaultSizeMode -int 2Avoids creation of .DS_Store and AppleDouble files.
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool trueAvoids creation of .DS_Store and AppleDouble files.
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool trueopen http://www.github.comopen README.mdYou can open applications using -a.
open -a "Google Chrome" http://www.github.comopen /path/to/folder/open .To clear font caches for all users, put sudo in front of this command.
atsutil databases -removeUser && \
atsutil server -shutdown && \
atsutil server -pingnetworksetup -listallhardwareportssystem_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p'system_profiler SPDisplaysDataType | grep Resolutionsysctl -n machdep.cpu.brand_stringPrevent sleep for 1 hour:
caffeinate -u -t 3600sudo pmset -gsudo pmset displaysleep 15sudo pmset sleep 30sudo systemsetup -getcomputersleepsudo systemsetup -setcomputersleep 60sudo systemsetup -setcomputersleep NeverPlay iOS charging sound when MagSafe is connected.
defaults write com.apple.PowerChime ChimeOnAllHardware -bool true && \
open /System/Library/CoreServices/PowerChime.appdefaults write com.apple.PowerChime ChimeOnAllHardware -bool false && \
open /System/Library/CoreServices/PowerChime.appdefaults write -g NSAutomaticSpellingCorrectionEnabled -bool falsedefaults write -g NSAutomaticSpellingCorrectionEnabled -bool truedefaults read -g NSAutomaticSpellingCorrectionEnabledDisable the default "press and hold" behavior.
defaults write -g ApplePressAndHoldEnabled -bool falseSets a very fast repeat rate, adjust to taste.
defaults write NSGlobalDomain KeyRepeat -int 0.02afconvert input.mp3 ringtone.m4r -f m4afsudo nvram SystemAudioVolume=" "osascript -e 'set volume output muted true'osascript -e 'set volume 4'You can play all audio formats that are natively supported by QuickTime.
afplay -q 1 filename.mp3say 'All your base are belong to us!'defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 1defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ProgramArguments -array "/usr/sbin/mDNSResponder" "-launchd"defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ProgramArguments -array-add "-NoMulticastAdvertisements"sudo ipconfig set en0 DHCPipconfig getpacket en0sudo dscacheutil -flushcache && \
sudo killall -HUP mDNSRespondersudo 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"ping -o github.comtraceroute github.comThis outputs all applications currently using port 80.
sudo lsof -i :80Create 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/airportRun a wireless scan:
airport -sdefaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences | grep LastConnected -A 7security find-generic-password -ga "ROUTERNAME" | grep "password:"- Fink - The full world of Unix Open Source software for Darwin.
- Homebrew - The missing package manager for OS X.
- MacPorts - Compile, install and upgrade either command-line, X11 or Aqua based open-source software.
cancel -a -defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true && \
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool truedefaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool truespctl --add /path/to/Application.appspctl --remove /path/to/Application.appFirst, install pwgen via Homebrew, etc.
pwgen -Cs 20 1 | tr -d ' ' | tr -d '\n' | pbcopy/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspendsrm /path/to/filesrm -r /path/to/folder/srm -rf /path/to/complete/destructionfind . -type f -name '*.DS_Store' -ls -deletesudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plistThe -i modifier makes the search case insensitive.
locate -i *.jpgdefaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool trueosascript /path/to/script.scptsudo rebootsudo poweroffsw_versHow long since your last restart.
uptimecat whatever.txt | pbcopypbpaste | expand | pbcopypbpaste > whatever.txtpbpaste | sort | uniq | pbcopysudo fdesetup statussudo sysdiagnose -f ~/Desktop/sudo kextload -b com.apple.driver.ExampleBundlesudo kextunload -b com.apple.driver.ExampleBundleRun job every 5 minutes.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.touchsomefile</string>
<key>ProgramArguments</key>
<array>
<string>touch</string>
<string>/tmp/helloworld</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
</dict>
</plist><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.touchsomefile</string>
<key>ProgramArguments</key>
<array>
<string>touch</string>
<string>/tmp/helloworld</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>45</integer>
<key>Hour</key>
<integer>13</integer>
<key>Day</key>
<integer>7</integer>
</dict>
</dict>
</plist><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.watchhostconfig</string>
<key>ProgramArguments</key>
<array>
<string>syslog</string>
<string>-s</string>
<string>-l</string>
<string>notice</string>
<string>somebody touched /etc/hostconfig</string>
</array>
<key>WatchPaths</key>
<array>
<string>/etc/hostconfig</string>
</array>
</dict>
</plist>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 -rsudo purgelaunchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist && \
killall -9 NotificationCenterlaunchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plistqlmanage -p /path/to/filedsenablerootdsenableroot -dnvram boot-argssudo nvram boot-args="-x"sudo nvram boot-args=""installer -pkg /path/to/installer.pkg -target /sudo softwareupdate -iaSet to check daily instead of weekly.
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1sudo softwareupdate -lmdutil -i off -d /path/to/volumemdutil -i on /path/to/volumemdutil -E /path/to/volumemdfind -name 'searchterm'Rings the terminal bell (if enabled) and puts a badge on it.
tput bel- iTerm 2 - A better Terminal.app.
- TotalTerminal - A system-wide terminal available on a hot-key.
Install the latest version and set as current users' default shell:
brew install bash && \
sudo echo $(brew --prefix)/bin/bash >> /etc/shells && \
chsh -s $(brew --prefix)/bin/bash- Homepage - The default shell for OS X and most other Unix-based operating systems.
Install the latest version and set as current users' default shell:
brew install fish && \
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.
Install the latest version and set as current users' default shell:
brew install zsh && \
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.
- Anonymous Pro - A family of four fixed-width fonts designed with coding in mind.
- 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.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
