When launched Terminal provides a line interface that you can use to control parts of the OS X interface - essentially it gives you access to the UNIX features that lie beyond the OS X skin. Here we will be looking at some projects that you can try out in Terminal, using your new found skills.
If you're new to Terminal, or need to brush up on your commands, the best place to start is our introductory feature which you can read here: How to use Terminal on a Mac.
1. How to alter file permissions using Terminal
File permissions control which users can access and modify files and folders on your Mac. Mostly they work very well, but occasionally things go awry, like when you copy a file from one user account to another and discover you can't open in it in your account.
There are two commands we can use to change permissions; chmod, which modifies permissions for all users except the file's owner, and chown which assigns ownership to a specific user.
So, to change permissions on a file to allow anyone to access, read, and modify the file, we'd use:
sudo chmod 777 path-to-file
Where path-to-file is the path of the file whose permissions you want to modify. Remember, rather than type the file path, you can drag the file onto the Terminal window. To modify the permissions to allow access and reading, but prohibit changing the file, swap 777 for 644.
If you want to change permissions on all the files in a folder, drag the folder onto the Terminal window instead of a file, and type -R after the command name.
To change ownership of a file to your account, use:
sudo chown your-short-user-name path-to-file
2. Change the default for screen shots on the Mac
By default, screenshots in OS X are saved as .png files. That's usually fine, but you can change it if you need to. For example, to change the default to jpeg, type:
defaults write com.apple.screencapture type JPG
You can also change to PDF or TIFF using the same command and swapping your chosen format for JPG.
To change the default name for screenshots, use:
defaults write com.apple.screencapture name "the-name-you've-chosen"; killall SystemUIServer
Replace the-name-you've-chosen with whatever you like and screenshots will now be given that name followed by the date and time.
3. Watch an ASCII version of Star Wars on the Mac using Terminal
This one's just for fun, but what fun! There's an ASCII version of Star Wars running on a Telnet server in The Netherlands. To watch it, use:
To stop it, type Ctrl-] and then 'quit'
4. Enable text selection in Quick Look on the Mac using Terminal
Quick Look is an incredibly useful tool for quickly examining the contents of a file. And while it's primarily intended for images, it can also be used to read text documents. Sadly, reading is as far as it goes. You can't select text to copy it, for example. At least, not without the help of a Terminal command. Type this to allow you to select text in Quick Look:
defaults write com.apple.finder QLEnableTextSelection -bool TRUE; killall Finder
5. Disable Auto-restore in Preview using Terminal on the Mac
Do you ever open Preview and find that it spews open document windows all over your screen? That's the fault of Auto-restore, a feature in OS X since Lion, which saves the state Preview is in when you quit it and then reverts to that state when you open it again. So, unless you close all open documents before quitting, they'll re-open next time you launch Preview.
To prevent that, and launch Preview without any documents, use this Terminal command:
defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool FALSE
To change back to the default, re-type the command, replacing FALSE with TRUE. To do the same thing in QuickTime X, replace com.apple.Preview with com.apple.QuickTimePlayerX
6. Make the Dock slide more quickly using Terminal on the Mac
If you use Show and Hide Dock, you'll notice that when you drag the mouse pointer onto the bottom of the screen, or whichever edge you keep the Dock, there's a delay before the Dock slides into view. You can eliminate that delay with these commands:
defaults write com.apple.dock autohide-delay -float 0
The '0' represents the delay before the Dock slides into view, so if you want to reduce it, but not eliminate it altogether, replace the '0' with another value, measured in seconds.
To revert to the default, type:
defaults delete com.apple.dock autohide-delay
You can also change the speed at which the Dock slides. Again, it's done by modifying a delay. So, to make it instant, type:
defaults write com.apple.dock autohide-time-modifier -float 0
To double the speed, replace the '0' with '0.5' and to keep it the way it was, use '1.'
7. Add a message to the log in window in Terminal on the Mac
Whether it's to prank other users, provide daily affirmations or inspiration to yourself, or for any other reason, there may be occasions when you want to put a message in the login window in OS X. With the help of Terminal, it's very easy. Type:
$ sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Your message here"
The next time you log out or restart, the message will appear in the log in window. To remove it, use:
$ sudo defaults delete /Library/Preferences/com.apple.loginwindow
8. Make your Mac speak using Terminal
You can make your Mac say anything you want in the currently selected voice. To do that, use the 'Say' command, like this:
Say "whatever you want your Mac to say"
As soon as you hit Return, your Mac will speak the words you typed.
9. Get rid of Dashboard on the Mac using Terminal
Let's face it, who uses Dashboard anymore? For most of us, the only clue to its continued existence is its appearance in Mission Control. If you'd like it gone completely, use this command:
defaults write com.apple.dashboard mcx-disabled -boolean TRUE
To bring it back, use the same command, but replace TRUE with FALSE.
10. Rebuild Spotlight using Terminal on the Mac
Spotlight is OS X's search tool and one which is incredibly useful. Occasionally, however, it can become corrupt or stop working properly. The solution is to rebuild it. Guess what? Yes, theres a Terminal command for that too. Use:
sudo mdutil -E /Volumes/DriveName
Where 'DriveName' is the name of the volume whose index you want to rebuild. In most cases, this will be your startup volume, and unless you've changed it, it will be called 'Macintosh HD.' Alternatively, if you have volumes mounted on your Mac's Desktop, you can drag the one you want onto the Terminal window, and ignore '/Volumes/DriveName.'