oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Cloning Terminal to Ease Window Management
Pages: 1, 2

Window Titles

It's easy to change the "Title" information that is used on each window. Pull down Terminal > Window Setting from the Menu Bar, then select the "Window" category. Change the "Title" fill-in to "TS2" (Terminal Set 2). Note that each copy of the app has its own preferences, window settings, etc. So, if you want to make a global change, you'll have to adjust each copy.

Menu Bar

If you have Xcode installed, you can change the Menu Bar to read "Terminal_2" (or whatever). Navigate to the Contents/Resources/English.lproj folder and double-click on Terminal.nib. After Interface Builder has started up, double-click on the "Terminal" string in "Terminal.nib (English) - MainMenu" and fill in the desired value (e.g., Terminal_2). Save and Quit.

Now, double-click on InfoPlist.strings. When a text editor window appears, change the value of CFBundleName to the same text string. Save and Quit. The next time you start up Terminal_2, the Menu Bar will read correctly.

Shell Support

It's handy for shell scripts to be able to find out which terminal set they're in. It's useful, for example, in dynamically setting window titles or command-line prompts. My current solution, which is a bit scary, is to edit the executable binary for the application. If you're comfortable with this idea, read on...

This hack is based on the fact that Terminal sets up a pair of environment variables for its sessions. One of these, TERM_PROGRAM, is normally set to Apple_Terminal. By editing Terminal's executable, we can change this value to a different text string.

Navigate to the Contents/MacOS folder. Using a binary-capable text editor (e.g., BBEdit), open the original executable. Search for the text string Apple_Terminal. In my executable, it is preceded by TERM_PROGRAM and followed by the string TERM_PROGRAM_VERSION, but Your Mileage May Vary.

Select the part of the string you wish to change and replace it with an equal number of characters. (I use Apple_Term_TS2 for Terminal_2.) Save and Quit. The next time you start up the app, this string will be available in TERM_PROGRAM.

If you're comfortable with scripting languages such as Perl, you might enjoy writing a special-purpose script to edit the file. I hacked together a script that edits TERM_PROGRAM, based on the name of the app in which the executable resides.

Final Thoughts

After a week or so of intensive use, this hack seems to be "wearing well." No crashes (or even glitches), and it provides the desired flexibility without adding more confusion to my life.

I would caution against setting up too many terminal sets, however, lest you get confused about what lives where. I currently have four terminal sets configured:

  • TS1 - administrivia and miscellanea
  • TS2 - my "work" project
  • TS3 - my "hobby" project
  • TS4 - unassigned, as yet

Although this exercise uses Terminal as its target app, the same sorts of changes could be made to any app. By (a) breaking up apps into phalanxes of files, and (b) giving us the tools to edit these files, Apple has given its users quite a bit of freedom. Not as much as an Open Source application would provide, to be sure, but still very handy on occasion.

Although he bears no blame for any of my ideas or mistakes, David Hill was splendidly helpful in my effort to change the app's title in the Menu Bar. Having worked closely with David in co-authoring the Mac OS X Technology Guide to Spotlight for SpiderWorks, I expected no less. Nonetheless, it's nice to have one's positive expectations confirmed.

Rich Morin are long-time users of both Mac OS and Unix. For obvious reasons, they find Mac OS X to be totally delightful.

Return to the Mac DevCenter