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 true
defaults write com.apple.universalaccess reduceTransparency -bool false
osascript -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.RemoteDesktop
defaults write com.bohemiancoding.sketch3 exportCompactSVG -bool yes
This 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 1800
hash tmutil &> /dev/null && sudo tmutil disablelocal
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
Function 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/icon_16x16@2x.png
sips -z 32 32 $1 --out $filename.iconset/icon_32x32.png
sips -z 64 64 $1 --out $filename.iconset/icon_32x32@2x.png
sips -z 128 128 $1 --out $filename.iconset/icon_128x128.png
sips -z 256 256 $1 --out $filename.iconset/icon_128x128@2x.png
sips -z 256 256 $1 --out $filename.iconset/icon_256x256.png
sips -z 512 512 $1 --out $filename.iconset/icon_256x256@2x.png
sips -z 512 512 $1 --out $filename.iconset/icon_512x512.png
cp $1 $filename.iconset/icon_512x512@2x.png
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 --override-system-vim --with-luajit --with-python
xcode-select --install
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)'
bless --folder "/path/to/mounted/volume/System/Library/CoreServices" --bootinfo --bootefi
hdiutil attach /path/to/diskimage.dmg
hdiutil detach /dev/disk2s1
You don't have to use the Disk Utility GUI for this.
sudo diskutil repairPermissions /
bless --mount "/path/to/mounted/volume" --setBoot
diskutil list
Supported formats are plain text, rich text (rtf) and Microsoft Word (doc/docx).
textutil -convert html file.ext
chflags hidden /path/to/folder/
Show All Hidden Files
defaults write com.apple.finder AppleShowAllFiles true
defaults write com.apple.finder AppleShowAllFiles false
chflags nohidden ~/Library
defaults write com.apple.finder CreateDesktop -bool false && killall Finder
defaults write com.apple.finder CreateDesktop -bool true && killall Finder
To clear font caches for all users, put sudo
in front of this command.
atsutil databases -removeUser && atsutil server -shutdown && atsutil server -ping
networksetup -listallhardwareports
system_profiler SPDisplaysDataType | grep Resolution
Prevent sleep for 1 hour:
caffeinate -u -t 3600
sudo pmset -g
sudo pmset displaysleep 15
sudo pmset sleep 30
sudo systemsetup -getcomputersleep
sudo systemsetup -setcomputersleep 60
sudo systemsetup -setcomputersleep Never
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool true
defaults read -g NSAutomaticSpellingCorrectionEnabled
afconvert input.mp3 ringtone.m4r -f m4af
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.mp3
say 'All your base are belong to us!'
defaults 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 DHCP
ipconfig getpacket en0
sudo dscachutil -flushcache && sudo killall -HUP mDNSResponder
You need to run all of the commands since the hostname needs to be changed in three places.
sudo scutil --set ComputerName "newhostname"
sudo scutil --set LocalHostName "newhostname"
sudo scutil --set HostName "newhostname"
ping -o github.com
traceroute github.com
This outputs all applications currently using port 80.
sudo lsof -i :80
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
defaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences | grep LastConnected -A 7
security 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 -
spctl --add /path/to/Application.app
spctl --remove /path/to/Application.app
First, 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 -suspend
srm /path/to/file
srm -r /path/to/directory/
srm -rf /path/to/complete/destruction
find . -type f -name '*.DS_Store' -ls -delete
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
The -i
modifier makes the search case insensitive.
locate -i *.jpg
osascript /path/to/script.scpt
sudo reboot
sudo poweroff
sw_vers
cat whatever.txt | pbcopy
pbpaste | expand | pbcopy
pbpaste > whatever.txt
pbpaste | sort | uniq | pbcopy
sudo fdesetup status
sudo sysdiagnose -f ~/Desktop/
sudo kextload -b com.apple.driver.ExampleBundle
sudo kextunload -b com.apple.driver.ExampleBundle
Run 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 -r
sudo purge
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist && killall -9 NotificationCenter
launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
qlmanage -p /path/to/file
dsenableroot
dsenableroot -d
nvram boot-args
sudo nvram boot-args="-x"
sudo nvram boot-args=""
installer -pkg /path/to/installer.pkg -target /
mdutil -i off -d /path/to/volume
mdutil -i on /path/to/volume
mdutil -E /path/to/volume
mdfind -name 'searchterm'
Rings the terminal bell (if enabled) and puts a badge on it.
tput bel
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.