Quickly Access the Sound and Displays Preference Panes
If you’re a laptop user who opens the Sound and Displays preference panes a lot—to change sound input or adjust a secondary monitor’s position, for example—you may be interested in undocumented shortcuts that take you directly to them from any application.
On your iBook or PowerBook, you can open either preference pane by holding down the option key and then pressing one of the volume- or brightness-controlling function keys (for Sound and Displays, respectively). So option-F1 or -F2 will open the Displays pane, and option-F3, -F4, or -F5 will open the Sound pane. If you have a desktop Mac and an Apple keyboard with volume controls, you can hold down option and press any of the volume keys at the top of the keyboard to open the Sound pane. Unfortunately, there’s no shortcut to the Displays pane for desktop Mac users.
Numerically Order Terminal File Listings
Working with numbered files in Terminal is somewhat frustrating because the app doesn’t properly sort the files in directory listings. Consider a simple directory containing 20 versions of a graphic— Logo-version 1, Logo-version 2, and so on. If you use the
command (which lists one file per row of output) on this directory, you’ll see something like this:
If you’re tracking revisions, or otherwise looking for a file in a large group of files, this manner of sorting can be problematic. However, using Unix’s ability to combine simple commands via the pipe (
) symbol, you can display files in numerical order, with
1, and so on.
The key to this trickery is the
command, which does what its name suggests—it sorts what it’s given as input. Adding the
option will sort data numerically.
also needs to know which portion of the data you’d like it to sort by. You direct it by specifying a starting point within the string of text to be sorted, stated in terms of a field number and then a character position within that field. Fields are groups of characters separated by spaces; in this example, there are two fields in the file name. The first field (numbering starts 0, not 1) is the Logo-version portion of the file name (or field 0). The second field (or field 1) is the version number. You don’t need to specify a location number within a field unless you want the sort command to start somewhere other than the beginning of the field.
Putting it all together, to sort the example output in numerical order, you’d type
ls -1 | sort -n +1
, which means “print a directory list, send its output to sort, and sort it numerically by the second field.” When you run the command, you’ll get a nicely organized list of your files that begins like this:
You can also use the optional character position for sorting numbered files that are lacking spaces in their names. For instance, for a series of files named ClientStuff1.txt, ClientStuff2.txt, and so on, you’d use the command
ls -1 | sort -n +0.11
. Since there are no spaces in the file names, there’s only one field (field 0), and the numeric portion of the file names starts at the 12th character (position 11, since numbering starts at 0).
Move (Don’t Copy) Files between Disks
If you have more than one hard drive or partition in your Mac, you probably know that dragging an item from one volume to another copies it instead of moving it. If moving is what you’re after, you need to copy the item and then delete the original.
An easier way to achieve the same result is to start the process as usual (click and drag the item), but before you release the mouse button at the destination, hold down the Command key. Now take your finger off your mouse, and the Finder will take care of moving the file from the source to the destination—saving you the trouble of removing the original.
Use the Inspector to View Previews
The Finder’s column view is a great way to see a bunch of information about a selected file. You can even play movies and sounds directly from column view. But if you prefer icon or list view, why should you have to give up the benefits of column view?
You probably know about OS X’s Get Info window (Command-I or File: Get Info, with any item selected in the Finder), whose Preview area will allow you to play audio and video files. However, opening a Get Info window for each file you want to preview is time-consuming and wastes screen real estate.
Get Info has a more powerful cousin called the Inspector, which you activate by pressing Command-option-I with an item selected in the Finder. The Inspector looks just like the Get Info window, but it’s dynamic. As you select new files in the Finder, the contents of the Inspector window change to reflect the current selection, so you can easily access previews of all your files while still benefiting from icon- and list-view windows. Just open the Inspector in an unused portion of your screen, and leave it there while you browse. That way, when you want to preview a video or listen to an audio clip, it’s just a mouse click away.
Contributing Editor Rob Griffiths is the author of the recently released
Mac OS X Power Hound, Panther Edition
(O’Reilly, 2004) and runs the
Mac OS X Hints
Using the Inspector window, you can reap the benefits of column-view windows—with previews of sounds and movies—without having to change from list- or icon-view windows.
Unix Tip of the Month: Images Are Everything
OS X is a treasure trove of hidden icons and images that you can use for everything from presentations to folder icons to desktop pictures. Hunting for these hidden images, however, can be frustrating. Most are stashed within an application’s bundle, or in hidden Unix directories—neither of which is easily searchable from the Finder. And that’s where Terminal comes in handy.
Your first step is to make sure that Unix knows where on your system all the files are. A Unix program called locate creates a list of files on your machine and allows you to search that list, and it runs automatically at regular intervals—if you leave your Mac on all the time. To update the file list by hand, open Terminal and type
, press return, enter your admin password, and go grab a snack—the update will take several minutes to run.
The key to treasure hunting with locate is to combine it with grep, a Unix program that matches patterns in text strings, such as file names and directory paths. Say you want to find all the TIFF images related to Apple’s iSync application. Just type
locate ".tiff" | grep "iSync" | more
and press return. This complex search command is actually relatively simple. First, locate is used to find all
files on your machine. That long list, which you won’t see, is then sent (via the Unix pipe symbol) to grep, which looks for the word
Finally, those results are sent to the program more, which does nothing more than pause the output after each screenful. Presto, you’ve got an instant list of every TIFF file related to iSync. To open any of the images in Preview, copy and paste an entire row from the list in Terminal with the command
. Press return, and the image opens in Preview.
There’s additional syntax for the locate program that’s very useful. If you run
locate * | more
, you’ll see the entire contents of the locate file. This will help you overcome a key limitation of locate—the fact that it’s case sensitive. So a search for
will find different files than a search for
To work around this case sensitivity, you can use the
command, which lets you ignore case. Say you’re looking for folder icons in the System folder. You’re not sure exactly how these icon files are named, but you’re guessing that they have
somewhere in their names. Try this command to see them all:
locate * | grep -i "folder" | grep -i ".icns" | grep -i "System" | more
This is the same as the first example, except it takes a few more trips through grep. First, you’re searching the entire file for
flag, which tells grep to ignore case when searching. This list is then searched for
again in a case-insensitive manner. Finally, the command finds any remaining lines that contain
this time paying attention to case, since you want to search the System folder.
Check It Out: “Wreck a Nice Beach” in Less Space
If the title of this tip makes no sense to you, it may help to know that part of it was in the code name for the Apple project that added speech recognition to Mac OS—just say the part in quotation marks quickly, and you’ll see why.
In any event, if you use speech recognition, you’re quite familiar with the floating bubble that lets you manage the process. Unfortunately, if you’re working on a small screen, the bubble often winds up exactly where you don’t want it to be. But it doesn’t have to be that way. You can minimize the speech bubble. Just double-click on the gray-lined area just below the middle, and the bubble will glide into the Dock.
Don’t worry—speech recognition will work just as it did before. In fact, the docked icon updates when you press the speech-activation key and speak.A few Unix commands can help you quickly find hidden treasures in OS X, such as this list of folder icon files in the System folder.