sourcecode
techy
<code>
#!/usr/bin/perl
use Getopt::Long;
use strict;
use warnings;
my $foreground = 0;
my $transparency = 1;
my $alpha = 80;
my $help = 0;
my $result = Getopt::Long::GetOptions(
'fg|foreground' => \$foreground,
'transparency!' => \$transparency,
'alpha:i' => \$alpha,
'help|?' => \$help,
);
die "Usage: $0 [--alpha <number>] [--foreground] [--[no]transparency] [--[no]dark]\n"
if @ARGV or not $result or $help;
die "Option 'alpha' must be between 0 (transparent) and 100 (opaque)\n"
if $alpha < 0 or $alpha > 100;
$alpha = 100 unless $transparency;
$alpha = ( $alpha * 65535 ) / 100;
my ($bg, $bg1, $fg) = random_colors( );
($fg, $bg) = ($bg, $fg) if $foreground;
$" = ", ";
open(OSA,"|-", "osascript");
print OSA <<SCRIPT;
tell front window of app "Terminal"
set background color to {@$bg, $alpha}
set normal text color to {@$fg}
set bold text color to {@$bg1}
set cursor color to {@$bg1}
end tell
SCRIPT
close(OSA);
exit 0;
sub random_colors {
my @rgb = map { int rand 256 } 1 .. 3;
my $lum = ($rgb[0] * 0.3) + ($rgb[1] * 0.59) + ($rgb[2] * 0.11);
my @rgb_bold = map { ( ( $_ + 128 ) % 256 ) * 257 } @rgb;
@rgb = map { $_ * 257 } @rgb;
my @rgb_fg = $lum < 128 ? (65535, 65535, 65535) : (0, 0, 0);
return (\@rgb, \@rgb_bold, \@rgb_fg);
}
</code>
I recently got a new iBook to play around with. My only disappointment was that the default Terminal.app uses the standard boring black text on white background. Inspired by the perlmonks node "[id://305198]" as well as <a href="http://www.macosxhints.com/article.php?story=20040823015557368">this</a> article on macosxhints, I wrote a script to dynamically change the colors of Terminal.app on each login.<p>
<readmore>
Supported options include:<p>
<ul>
<li>--alpha - set alpha (transparency) level between 0 (transparent) and 100 (opaque)
<li>--foreground - Swap foreground and background colors for a subtler effect
<li>--(no)transparency - Turn on (default) or off transparency
<li>--help - Get help
</ul>
<p>
This code cheats by using "osascript" and <a href="http://www.apple.com/applescript/terminal/">applescript</a> to tell Terminal.app to change colors. To run this script on login, add a call to it from your .profile (if using the default bash shell). This script should also be easily modifyable to work with other terminals/xterms/etc.
Miscellaneous
Nathan Byrd (nathan@byrd.net)