Sun Dublan
RandomTint.pl 
#!/usr/bin/perl

# A script for the Apple Terminal on MacOS X which edits the
# com.apple.Terminal.plist in your preferences folder to provide you
# with a random tint for each terminal.  To get it to run every time
# you start your terminal, place something like this in your
# ~/.tcshrc:
#
# if ($?prompt) perl ~/RandomTint.pl

use strict;
use vars qw($dark $opacity $threshold);

##
## Settings
## ------------
$opacity = 0.85;  # from 0 to 1
$dark = 0;        # 1 = do dark colors, 0 = don't do dark colors
$threshold = 0.4; # between 0 and 1.
## ------------
## End Settings
##

my $defaults = "/usr/bin/defaults";
my $domain =  "com.apple.Terminal";

my $TextColors      = `$defaults read $domain TextColors`; 
my $TerminalOpaqueness = `$defaults read $domain TerminalOpaqueness`; 
my $i               = '\d\.\d\d\d\s';  # float 1.3 regexp
my $cg              = "$i$i$i";        # three of the above in a row
chomp $TextColors; chomp $TerminalOpaqueness;

system("$defaults write $domain TerminalOpaqueness $opacity")
  if ($TerminalOpaqueness != $opacity);

# dump each float triplicate into an array
my $x               = 0; 
my @color           = ();
while ($TextColors  =~ /($cg)/g) { $color[$x] = $1; $x++}

# generate colors depending on thresholds
my @new_colors = &new_colors();

# array element 4 is the one we want to randomize.  The higher (closer
# to 1) they are, the more vibrant the colors will be.  Lower numbers
# will cause more bland colors.
$color[4]           =
    sprintf ("%.3f %.3f %.3f ", @new_colors);

# make a new string
my $newTextColors   = undef;
for (@color) { $newTextColors .= $_ }

# write the string
system("$defaults write $domain TextColors \"$newTextColors\"");

# uncomment for debug
#print $newTextColors . "\n"; exit 0;

sub new_colors {
  my @new_colors = ();
  my $rand_threshold = $threshold;
  if (!$dark) { $rand_threshold = (1 - $threshold) }

  for $x (0..2) {
    my $rand = rand($dark ? $threshold : 1 - $threshold);
    $new_colors[$x] =  ($dark ? $rand : $rand + (1 - $threshold));
  }

  return @new_colors;
}
11/25/2006 Webmaster: Troy Bowman