Learning the Mac OS X Terminal, Part 4by Chris Stone
The series continues in Learning the Terminal in Mac OS X, Automating Mail from the Mac OS X Terminal, Configuring Email from the Mac OS X Terminal, Customizing the Mac OS X Terminal, and Synchronizing Drives with Cron and the Mac OS X Terminal.
In the first three parts of this series, you got your hands good and dirty learning to work the Unix command line. Now it's time to have a bit of fun with a very cool feature of the Terminal application, term files.
Before you get started on this tutorial, you'll need to have the Apple Developer Tools installed, if you don't already. You'll know if they're installed if you have a /Developer directory on your disk. If you don't, and don't have a copy of the installer CD, you can download a disk image free from Apple after signing up for an Apple Developer Connection (ADC) membership here.
As you might have already discovered, Terminal provides you with lots of ways to customize its windows. You can set text and background colors, window size, title bar text, and much more.
These changes become your global defaults (applying to all new windows) when you use the Preferences palette (Terminal --> Preferences), or you can apply them to individual windows by using the Inspector palette (Shell --> Inspector).
Term files are the third method for saving window settings. They allow you to save these individual window settings to a file, which when opened, creates a new window with all of your pre-configured settings. Using term files you can quickly open several new windows, each with different, pre-defined settings.
Things really become interesting, however, when you take advantage of a little known feature of term files, the ability to define a command line to run when the window opens. Doing this allows you to create your own double-clickable run files that open in Terminal within a window of your exact specifications and run any command line (or script file) you can come up with.
This tutorial will walk you through the simple process of creating just such a term file. Along the way, you'll also learn about editing plist-like XML files, installing Unix applications, and even a bit about Internet MP3 streams.
To use as a good example for this tutorial, I've chosen Streamripper, the open source Unix application that allows you to "rip" MP3 files to your hard disk from some streaming MP3 "Internet radio stations," including many of those listed in the iTunes Radio Tuner.
This article introduces the command line version of Streamripper to demonstrate the use of term files. However, if you would like to check out a full Aqua GUI version of Streamripper, you can find one called StreamCatcher here.
You'll learn more about Streamripper in a bit, but first let's configure your Terminal window and save the settings to a term file. Of course you can set up your window to look however you like, but for purposes of the tutorial I'm going to try to make a window that looks something like an LCD display.
To start, open Terminal and its Inspector palette. From the Inspector's pop-up menu select Window. The default width of 80 columns will do nicely, but you'll only need 5 rows of text. Check only the Custom Title checkbox, and in its field enter: "Type Control + C to Stop." These instructions will remind you how to stop Streamripper.
Next, you'll want to pick a nice looking font and color-scheme for the window. I kind of like the look of the iTunes LCD-like window, so we'll try to duplicate that with our Terminal window settings. First, select Text from the Inspector pop-up. I've set the cursor to be as invisible as possible (an underline), and unchecked everything else.
The iTunes window uses 10-point Lucida Grande, but since it isn't a mono-spaced font it doesn't look so good in a Terminal window. So instead, I chose one of the mono-spaced fonts, VT100 12-point, which is close enough.
To set the colors, select Colors from the Inspector's pop-up. Double-click the Background color swatch to open the color palette. To duplicate the iTunes color, I used the magnifying glass tool found at the bottom of the Color palette to grab the color from an iTools window. Do the same with the Cursor color swatch as well.
Finally, to remove the scroll bars from the Terminal window, select Buffer from the Inspector and check to disable the buffer, uncheck line wrapping, and check to scroll to bottom. Your window should now look something like this:
You're almost ready to save these setting as a term file, but before you do, you should first place the window where you would like it to open within your display since this setting is saved in the file as well.
When you're ready to save the file, select Save from the Shell menu. You'll need to save it in the
~/Library/Application Support/Terminal directory. However, it's likely you don't yet have a Terminal folder in
/Library/Application Support, so you'll first need to create one from within the Save dialog box. Name the file "streamripper.term" and save it there.
|Post your Terminal questions and comments right here!|
Notice also the two options at the bottom of that Save dialog box. While they won't apply to this procedure, they can be very useful for other term files you might want to create. The first option allows you to choose either to save the settings for only the "Main Window," that is, the active window, or save the settings for all open windows to a single term file.
The possibilities are indeed endless when selecting the later choice. You could create a term file to open three or four or more windows at once, all laid out neatly across your monitor, each with its own size, color schemes, etc. and each even running a different command! As you get more familiar with Unix, you might consider setting up multiple windows, some logged into different
ssh sessions, another window running
top, and maybe another running Streamripper, for example.