Useful OS X Commands

Apple Icon - OSX

Useful OS X Commands

Here is a list of a bunch of potentially useful OS X Commands. These are going to be mostly for power users, system admins, OS X hackers, and programmers. Normal users will likely never need these, thus they are presented without use directions.

Commands were gathered via the .OSX group on GitHub. Please feel free to comment below and add any other useful commands you find!

Most commands are set to enable the action with the -true flag. Disable action by replacing it with -false.

Stop the creation of .DS_Store and AppleDouble files on USB Drives
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true

Stop the creation of .DS_Store files on Network Drives
defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Show hidden files in Finder
defaults write com.apple.finder AppleShowAllFiles YES

Prevent MDS from attempting to Index
sudo touch /Volumes/your volume name here/.metadata_never_index

Disable Indexing and Searching of Volumes
sudo mdutil -i off -d /Volumes/VolumeName

Delete existing Spotlight Index
sudo rm -rfv /.Spotlight-V100

Enable full keyboard access for all controls
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

Enable subpixel font rendering on non-Apple LCD Screens and non-Retina Monitors
defaults write NSGlobalDomain AppleFontSmoothing -int 2

Show the ~/Library folder in GUI (Can be used to show other “hidden” folders that some Applications add)
chflags nohidden ~/Library

Add “Anywhere” option to the “Allow apps downloaded from:” under the General Tab of Security and Privacy
sudo spctl –master-disable

Enable the 2D Dock
defaults write com.apple.dock no-glass -bool true

Turn Dock autohide on
defaults write com.apple.dock autohide -bool true

Remove Dock display delay
defaults write com.apple.Dock autohide-delay -float 0 && killall Dock

Show Dock icons of hidden applications as translucent
defaults write com.apple.dock showhidden -bool true

Show iTunes track notifications in the Dock
defaults write com.apple.dock itunes-notifications -bool true

Disable menu bar transparency
defaults write NSGlobalDomain AppleEnableMenuBarTransparency -bool false

Show remaining battery life as percentage
defaults write com.apple.menuextra.battery ShowPercent -string “YES”

Show remaining battery life as time
defaults write com.apple.menuextra.battery ShowTime -string “YES”

Always show scrollbars
defaults write NSGlobalDomain AppleShowScrollBars -string “Auto”

Hide desktop icons upon quitting Finder
defaults write com.apple.finder QuitMenuItem -bool true

Disable get info and window animations in Finder
defaults write com.apple.finder DisableAllAnimations -bool true

Show all filename extensions in Finder
defaults write NSGlobalDomain AppleShowAllExtensions -bool true

Use current directory as default search scope in Finder
defaults write com.apple.finder FXDefaultSearchScope -string “SCcf”

Show Path bar in Finder
defaults write com.apple.finder ShowPathbar -bool true

Show Status bar in Finder
defaults write com.apple.finder ShowStatusBar -bool true

Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true

Expand print panel by default
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true

Disable dialog box: “Are you sure you want to open this application?” (Note, this disables OS X Security and anti-malware features)
defaults write com.apple.LaunchServices LSQuarantine -bool false

Disable dialog box: “Are you sure you want to open this application?” (for one application)
xattr -d com.apple.quarantine ~/Downloads/ApplicationName (before installing)
xattr -dr com.apple.quarantine /Applications/ApplicationName (after installing)

Disable shadow in screenshots
defaults write com.apple.screencapture disable-shadow -bool true

Enable highlight hover effect on Dock for the grid view of a stack
defaults write com.apple.dock mouse-over-hilte-stack -bool true

Enable spring loading for all Dock items
defaults write enable-spring-load-actions-on-all-items -bool true

Show indicator lights for open applications in the Dock
defaults write com.apple.dock show-process-indicators -bool true

Don’t animate opening applications from the Dock
defaults write com.apple.dock launchanim -bool false

Display ASCII control characters using caret notation in standard text views
(Try e.g. `cd /tmp; unidecode “\x{0000}” > cc.txt; open -e cc.txt`)
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true

Disable press-and-hold for keys in favor of key repeat (enable key repeat)
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

Set keyboard repeat rate
defaults write NSGlobalDomain KeyRepeat -int 0.05 (Fast)
defaults write NSGlobalDomain InitialKeyRepeat -int 15 (Slow)

Disable auto-correct (Does not impact MS Office)
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false

Disable opening and closing window animations
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false

Enable AirDrop over Ethernet (also works for Lion)
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true

Disable disk image verification
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

Automatically open a new Finder window when a volume is mounted
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true (Read-only)
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true (Read-write)
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true

Display full POSIX path as Finder window title
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true

Increase window resize speed for Cocoa applications
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001

Disable the warning upon changing file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

Show item info below desktop icons
/usr/libexec/PlistBuddy -c “Set :DesktopViewSettings:IconViewSettings:showItemInfo true” ~/Library/Preferences/com.apple.finder.plist

Enable snap-to-grid for desktop icons (Same as OS 9 GUI command)
/usr/libexec/PlistBuddy -c “Set :DesktopViewSettings:IconViewSettings:arrangeBy grid” ~/Library/Preferences/com.apple.finder.plist

Disable Empty Trash Warning
defaults write com.apple.finder WarnOnEmptyTrash -bool false

Empty Trash securely by default
defaults write com.apple.finder EmptyTrashSecurely -bool true

Require password immediately after sleep or screen saver begins (reduces the normal delay)
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0

Enable tap to click on Trackpad
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true

Map bottom right Trackpad corner to right-click
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true

Disable Safari thumbnail cache for History and Top Sites
defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2

Enable Safari debug menu (most useful for Web Developers)
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true

Remove useless icons from Safari bookmarks bar
defaults write com.apple.Safari ProxiesInBookmarksBar “()”

Add a context menu item to web view for showing the Web Inspector
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true

Only use UTF-8 in Terminal Application
defaults write com.apple.terminal StringEncodings -array 4

Disable the Ping sidebar in iTunes
defaults write com.apple.iTunes disablePingSidebar -bool true

Disable Ping in iTunes
defaults write com.apple.iTunes disablePing -bool true

Make ⌘ + F focus the search input in iTunes
defaults write com.apple.iTunes NSUserKeyEquivalents -dict-add “Target Search Field” “@F”

Disable send and reply animations in Mail Application
defaults write com.apple.Mail DisableReplyAnimations -bool true
defaults write com.apple.Mail DisableSendAnimations -bool true

Disable Resume system-wide
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

Disable the “reopen windows when logging back in” dialog box (Leaves default to reopen windows)
defaults write com.apple.loginwindow TALLogoutSavesState -bool false
defaults write com.apple.loginwindow LoginwindowLaunchesRelaunchApps -bool false

Enable Dashboard Dev mode (Keeps widgets on the desktop)
defaults write com.apple.dashboard devmode -bool true

Reset Launchpad
[ -e ~/Library/Application\ Support/Dock/*.db ] && rm ~/Library/Application\ Support/Dock/*.db

Disable local Time Machine backups
hash tmutil &> /dev/null && sudo tmutil disablelocal

How To: Flush DNS Cache on OS X

Most users don’t need to use this command, but it’s very helpful for web developers and network admins to troubleshoot issues with web sites.

This command is run via terminal.

On Leopard (10.6) and Snow Leopard (10.7):

(as root or admin user) dscacheutil -flushcache

On all other version (10.0 – 10.4):

(as root or admin user) lookupd -flushcache

How To: Tweak OS X “Spaces”

How To: Tweak OS X “Spaces”

Spaces is OSX’s cool virtual window program that allows “multiple” desktops to be setup. The thought is that it allows you to group programs together by task and thereby increasing your workflow productivity.

Apple has a great tutorial on how to really maximize it’s usefulness.

But some of us want to tweak it’s usability. For instance to disable the “teleport to another space feature” in terminal (as root)

defaults write com.apple.Dock workspaces-auto-swoosh -bool NO

killall Dock

To switch back:

defaults write com.apple.Dock workspaces-auto-swoosh -bool YES

killall Dock

To remove the animation between spaces:

defaults write com.apple.Dock workspaces-swoosh-animation-off -bool YES

killall Dock

Please comment and add any other tricks you have.

How To: Disable Dashboard in OS X

How To: Disable Dashboard in OS X

Dashboard in Leopard is a love it or hate it application. There are several useful applications that can make life easier. On the other hand, it’s easy to hit the activation buttons on Mighty Mouse by accident. Other people may begrudge Dashboard’s use of memory. It’s not much, but on low end machines every bit counts.

This is how to disable Dashboard:

Open Terminal (as an admin user)

type: defaults write com.apple.dashboard mcx-disabled -boolean YES

Hit Enter

type: killall Finder

When Finder restarts, Dashboard should be gone. To turn it back on follow the same instructions, but replace YES with NO.

The first command is the powerful one. There are a lot of default behaviors that can be changed in OS X if the write command is known.

The second command, killall Finder simply does the same as force quitting Finder from the GUI. It forces the Finder to quit, relaunch and reload everything, including the Dock. In this case it does not relaunch Dashboard though.

Please let me know if you find this helpful. Also suggestions for other terminal commands would be appreciated.