With three screens up 24/7, it's easy for me to accumulate windows. I typically have several dozen available on my Mac, spread across a few dozen apps. In general, this is quite convenient. When I'm not using an app, I hide it (via cmd-H) and all of its windows disappear. If I want to get only a few windows out of the way, I WindowShade them or send them to the Dock.
Unfortunately, these approaches don't work very well for applications that have lots of windows. Terminal programs, for example, may have dozens of windows, each presenting a different shell and/or application context. Mac OS X doesn't let me hide some of an app's windows, so that's out. The Dock and WindowShade are awkward ways to manage dozens of windows; simply dismissing and retrieving a set of several windows becomes quite a hassle.
Fortunately, there is a (relatively) simple workaround. By using multiple copies of an app (e.g., Terminal), I can hide and display each copy's windows separately. I currently have four copies of Terminal available. One is used for generic tasks, two are used for specific projects, and one is idle.
This arrangement is working well. Any new Terminal window I create (via cmd-N) becomes part of the current copy's set. I even found a way to let a script know which Terminal it's running under. Finally, although it might be nice to have the ability to migrate windows between sets, this has not been a serious deficiency in practice.
Here's a basic walk-through of the procedure. Feel free to season to taste; after all, it's your machine! However, if you're a bit paranoid, you may want to quit the relevant copies of Terminal before performing these steps.
Copy the preference file and the Terminal app.
Using the Finder, go to ~/Library/Preferences and copy com.apple.Terminal.plist to com.apple.Terminal_2.plist. Then, go to /Applications/Utilities and copy Terminal.app to Terminal_2.app.
Link up the app to the preference file.
Control-click on Terminal_2.app and select "Show Package Contents." In the Contents folder, double-click on the Info.plist file. In the resulting Property List Editor, change CFBundleIdentifier from com.apple.Terminal to com.apple.Terminal_2 (see Figure 1). Save and Quit to make the changes permanent.
Trim the foreign language support files (optional).
In the Resources folder, remove any superfluous *.lproj files. This can reduce the copy's disk storage by more than 60 percent.
You can now start up and play with the copied app. Some customization is also reasonable at this point. The following sections explain how to change the windows' titles, the app's name in the Menu Bar, and the value of the TERM_PROGRAM environment variable. The techniques become increasingly scary as we go along; feel free to bail out at any time.
|
Related Reading Running Mac OS X Tiger |
|
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.
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.
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.
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:
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
Copyright © 2009 O'Reilly Media, Inc.