Terminal Hacks

January 18th, 2010

To remove formatting, you might need to copy the commands to a text editor before pasting into the Terminal

Lock Screen via Keychain Access
Go to Keychain Access → Preferences…
Under General section, tick checkbox ‘Show Status in Menu Bar’

Securely Erase Free Space
Securely erases data on the free space of a Mac hard drive called Macintosh HD
diskutil secureErase freespace 3 /Volumes/Macintosh HD

Makes all links in Safari open as separate tabs, not separate windows
defaults write com.apple.Safari TargetedClicksCreateTabs –bool TRUE

Safari’s cache in the Terminal
See exactly where you’re surfing by executing the following command: dscacheutil -cachedump -entries Host
To purge Safari’s cache for real, execute this Terminal command: dscacheutil -flushcache

File System Check
Reboot your Mac while holding down Command-S.
At the command-line prompt type: /sbin/fsck –fy. After fsck does its Unix magic you will see one of the following messages: ** The volume (name_of_volume) appears to be OK. If you see that, you’re golden. Or you might see: ***** FILE SYSTEM WAS MODIFIED *****. If you see that, you need to run fsck repeatedly until you see the first message. > reboot

Add recent applications as a Stack on Dock
Creates a custom Stack on the Dock that will show your recently opened applications
defaults write com.apple.dock persistent-others -array-add ‘{ “tile-data” = { “list-type” = 1; }; “tile-type” = “recents-tile”; }’
killall Dock

Change Time Machine backup interval (default 3600 = 1 hour)
sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 1800

Enable “path view” in Finder
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
killall Finder

Gradient highlights for Stacks
Gives you a mouse-over gradient in your Stacks

defaults write com.apple.dock mouse-over-hilte-stack -boolean YES
killall Dock

Change your current screenshot format
defaults write com.apple.screencapture type png
logout/login

Make hidden Dock icons transparent
have all your application icons displayed as transparent

defaults write com.apple.Dock showhidden -bool YES
killall Dock

Disable Dashboard
defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock

Reset your Mac OS X password
Restart your machine in Single User Mode by holding down the Command Key and the “S” key.

At the terminal:

* #sh /etc/rc
* #passwd yourusername
* #reboot

HTML via the command line

textutil command that can take any .txt file and automagically turn it into a properly coded webpage:

textutil -convert html foo.txt

This produces a file called foo.html in the same directory without mangling the original text file.

Manually Run Maintenance Scripts
sudo sh /etc/daily
sudo sh /etc/weekly
sudo sh /etc/monthly

Clearing the Finder “Open With” contextual menu
If your Open With… menu is filled with too many choices to easily scroll through, you can remove the less-commonly used choices. These steps will clear the list except for the most current applications that can open your document.

1. From the Finder Go menu, choose Home.
2. Open the Library folder in the Home window.
3. Open the Preferences folder.
4. Find com.apple.LaunchServices.plist.
5. Rename “com.apple.LaunchServices”, such as to “com.apple.LaunchServices.old”, or move it to the Trash.

The next time you use the Open With…. contextual menu in the Finder, only current applications will be listed. Some items may return if the application that controls them adds itself back to the list.

iPhoto Maintenance
Hold down the OPTION-COMMAND keys while opening iPhoto until you will see this dialog box offering to: 1. Rebuild the small thumbnails, 2. Rebuild all thumbnails, 3. Rebuild the iPhoto Library database, 4. Recover orphaned photos.

Back Up Locations
/Applications
/Users/$user/Desktop
/Users/$user/Documents
/Users/$user/Movies
/Users/$user/Music
/Users/$user/Pictures
/Users/$user/Public/*
/Users/$user/Library/Application Support/*
/Users/$user/Library/Thunderbird/*
/Users/$user/Library/Safari/*

Expand Save Dialog
defaults write -g NSNavPanelExpandedStateForSaveMode -bool TRUE

Shows hidden files in the finder. Replace TRUE with FALSE to hide hidden files again
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

Comments are closed.