A script to cycle Terminal color/transparency settings

Aug 25, '04 10:00:00AM

Contributed by: Anonymous

I wrote a shell script that makes the Terminal not only transparent, but each time you open a new shell, it is a different color. This hint assumes you're running the tcsh shell; it should be relatively simple to modify it for the 10.3 bash default shell. Here's how I did it.

First, open a new Terminal window, and type the following commands:

$ mkdir .colors
$ cd .colors
This creates a hidden directory you'll use to hold your color terminal commands and script, and then switches to that directory. The next step is to create the color files that will tell the Terminal window to switch its background color. Read the rest of the hint for those steps, as well as the changes needed to make this work on each login.

To create the Terminal window color files, copy and paste these commands (skip the $ prompt if you're copying and pasting):

$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {47802,6909,1222, -20750}'" > col1.sh
$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {2570,33924,20, -20750}" > col2.sh
$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {21570,3324,5000, -20750}" > col3.sh
$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {30810,26728,12934, -20750}" > col4.sh
$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {23387,2313,59367, -20750}" > col5.sh
$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {2570,33924,46774, -20750}" > col6.sh
$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {59367,23387,2313, -20750}" > col7.sh
$ echo "osascript -e 'tell front window of app "Terminal" to \
set background color to {2313,5367,23387, -20750}" > col8.sh
$ chmod u+x col*.sh
Each of these lines creates a one-line file that executes an AppleScript to change the Terminal window's color (the last line tells the Terminal that the above files are executable, so they can be run as programs). The first three numbers in the curly brakcets are the color values needed to create certain on-screen colors; you can get ideas for different color values from the DigitalColor Meter in /Applications -> Utilities. Set the pop-up to "RGB as Actual Value, 16-bit" to see the values to use. The fourth value in the brackets (the negative one) represents the amount of transparency for the window. It can be adjusted accordingly, but I recommend that you don't put it above -1000 or the effect is basically unnoticeable. -20750 is the value that achieves the amount of transparency you'd see if you adjust the transparency slider to the fourth notch in the GUI. If you want solid windows, just remove this fourth value entirely.

The last step is to modify (or create, if you don't have one) your .login file. Type cd and hit return to jump back to your home directory, and then launch your favorite editor (vi, pico, etc.) on your .login file (e.g. vi .login). Once in the editor, add these lines:
/.colors/col1.sh
mv .colors/col1.sh .colors/tmpcolor.sh
mv .colors/col2.sh .colors/col1.sh
mv .colors/col3.sh .colors/col2.sh
mv .colors/col4.sh .colors/col3.sh
mv .colors/col5.sh .colors/col4.sh
mv .colors/col6.sh .colors/col5.sh
mv .colors/col7.sh .colors/col6.sh
mv .colors/col8.sh .colors/col7.sh
mv .colors/tmpcolor.sh .colors/col8.sh
The first line executes the first color-changing script. The remaining lines then rotate each of the additional scripts up one position in the 'queue,' so that the next time you open a Terminal window, you'll get a new color. Save the file and quit the editor. You can, obviously, use as many or as few color files as you like, just make sure you modify the .login rotation script to match the number of color files you've defined.

For all this trickery to work, open Terminal's Preferences and make sure the following options are set: That's it! Restart your Terminal, and watch the colors change as you open new windows.

Comments (37)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040823015557368