OS X Random Color Terminal

I've grown to love Terminal's tabbed interface in OS X. Tabs make it easy to manage multiple fullscreen terminal sessions, but it isn't always easy to tell at a glance which tab you currently have open. Wouldn't it be nice if there was a way to set the color of the tabs? Well, you can't do that. But you can do the next best thing.

Here's a little Perl script that will set your Terminal background to a random color. Now you just have to remember that your remote login tab is red, for example, while your home folder session is blue. Save this code as "rndterm" in your execution $PATH (e.g., /usr/local/bin) and then do chmod ug+x rndterm to make it executable. Finally, add "rndterm" to your .profile or .login file. Now your Terminal sessions are much more colorful. Use "rndterm bright" if you're using dark fonts on a light background.

#!/usr/bin/perl

#
# Look for the word "bright"
#

  $min = ($#ARGV==0 && $ARGV[0]=~/bright/i) ? 45500 : 0;

#
# Randomly generate a color
#
# RGB between  0 ...  65535
#   A between -1 ... -32768
#

  $r = int(rand(20000)) + $min;
  $g = int(rand(20000)) + $min;
  $b = int(rand(20000)) + $min;
  $col = "$r,$g,$b,-9000";

#
# Set the color right away
#
  `osascript -e 'tell front window of app "Terminal" to set background color to {$col}'`;

Of course you can also name your tabs as well!