Create customized Terminal command windows
For today’s geeky Friday, we’re going to look at a couple ways to make your use of the Terminal more efficient. These tips should benefit anyone from the most basic Terminal user to the advanced Unix guru, and everyone between (which is clearly where I fall, though closer to the ‘basic’ end of the scale!). None of what follows is super advanced, as this tip is based on some standard Terminal features that not everyone may know about.
If you use the Terminal to regularly perform some task, such as watching
to monitor system processes or using
to connect to another host, there are a number of ways to quicken the process. You can, of course, create an alias to make running the commands easier. But you’d still have to open a window yourself, and size/position it as you like. A much better solution is to use Terminal’s ability to create saved Terminal sessions. These sessions can have a completely customized look, and be set up to run any command you wish, and can then be activated through the Finder or from within the Terminal.
To start this process, open a new Terminal window, then choose Terminal: Window Settings. This will open a floating window with a pop-up list that lets you customize a number of things about the current window’s appearance. Go ahead and change whatever you wish, in each of the categories. Here are some ideas to get you started:
Use the Display section of the panel to change the font face and/or size for your customized Terminal session. For a
topcommand, for instance, you might be able to use a smaller font, since you don’t really need to stare at every line for any length of time.
Use the Color section to change the color scheme for your customized window. For instance, if you use
sshto connect to remote hosts, it could be useful for those windows have a different color than your local windows—set host1 to have a blue background, host2 to have a red background, etc. In this way, you can easily identify your remotely-connected Terminal windows.
Use the Window section to change the size of the Terminal window (or just resize it via the drag handles). A smaller window could be use for
top, for instance, since its display is relatively narrow. You could also set a customized title for the saved session you’re about to create—use “Remote to Host1,” for instance, to even more easily identify your remotely connected sessions.
- Do not click the ‘Use settings as defaults’ button—you don’t want these tweaked settings to be standard for all new windows, just for the one window you’re modifying.
Once you have everything set up as you wish it to appear, select File: Save As. In the new dialog that appears, give the saved session a name, leave the “What to Save” set to Main Window, and then click the ‘Execute this command (specify complete path)’ radio button. In the box below that, enter the command you’d like to run in your saved session, and make sure the “Execute this command in a shell” box is checked. For instance, this setup will save a customized command that edits my user’s
profile file using
Note: The process at this point differs slightly depending on if you’re running 10.3 or 10.4. In 10.3, the default save location will probably be your Documents folder. In 10.4, it should be pointing to a Terminal folder in your user’s Library: Application Support directory. If you’re running 10.3, you’ll want to switch out to the Finder, create that same Terminal folder in the same location on your system, and then switch back to Terminal and point the save dialog to that new folder. Terminal sessions saved to this location will then appear in Terminal’s File: Library menu. You can save them other places, if you wish, but the Library menu makes it really convenient to use the saved sessions, as seen here:
As you can see, I keep a number of saved sessions ready to go for easy use—two sessions do remote connections via
(and have different background colors and titles), one does a
session to watch system resource consumption, one edits Apache’s configuration file, and the Screenshot file sets a nice, simple black-on-white Terminal for Macworld screenshots.
So saved Terminal commands are really easy to use within the Terminal. But they can also be easily used from the Finder—just double-click any of the saved sessions, and that session will open in Terminal. You can make it even easier to do by dragging the Terminal folder onto the right side of your Dock; control-click on the folder and choose one of your saved commands from the pop-up menu.
Finally, here’s one last sorta cool thing you can do with saved Terminal sessions. By default, these saved sessions open up in a foreground Terminal window. But perhaps you don’t need to see the window right away. In my case, the
command can sit in the background, away from my eyes, until I want to see what’s up with the system. So I have it open in a minimized window in the Dock, instead of in the foreground. To do this, drag and drop a saved Terminal session onto TextEdit (or your preferred text editor). Search for this block of code:
Change it to look like this instead:
Save the file and quit the editor. When you use this saved session, the window will simply appear in your Dock, minimized, with the specified command already running. Amazingly handy…