Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'zeorge finally :) a super script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
zeorge finally :) a super script
Authored by: zeorge on Aug 27, '04 02:44:24PM

which i should not have coded because i got lotta work to do :)

save it as "setcolor.pl", do a "chmod +x setcolor.pl",
and call it as first line from your .tcshrc or bashrc.

it changes the color randomly selecting from a list.
it does not take the same color two times.
it does not use apple script
it is fast
its ugly coded (i know) but better than &*รง% applescript
it is really fast :)

[code]
#!/usr/bin/perl
# zeorge 08-2004 - terminal BG color changer - works with panther 10.3.5

# Colors to choose from, in R G B
@color_table = ( "0.200 0.000 0.000","0.000 0.200 0.000","0.000 0.000 0.200" );
$opaqueness = "0.95";

#defaults read com.apple.terminal TextColors
@text_colors = split " ",`defaults read com.apple.terminal TextColors`;

# get actual bg color
$pos = 1 ;
@bg_color[0] = @text_colors[$pos*3];
@bg_color[1] = @text_colors[$pos*3+1];
@bg_color[2] = @text_colors[$pos*3+2];

# Randomly select a Color BUT NOT THE SAME as the actual bg color
for(;;) {
$index = int(rand(scalar(@color_table)));
@colors = split " ", @color_table[$index];
last if("@colors" != "@bg_color");
}

# set selected color in TextColors array
# pos 1 and 4 of TextColors = background color

$pos = 1 ;
@text_colors[$pos*3] = @colors[0];
@text_colors[$pos*3+1] = @colors[1];
@text_colors[$pos*3+2] = @colors[2];
$pos = 4 ;
@text_colors[$pos*3] = @colors[0];
@text_colors[$pos*3+1] = @colors[1];
@text_colors[$pos*3+2] = @colors[2];

# ( pos 0 and 4 of TextColors = text color
# pos 2 and 3 of TextColors = text bold color
# pos 6 of TextColors = selection color
# pos 7 of TextColors = cursor color )

# Set the new background color via the 'defaults' command
system("defaults","write","com.apple.terminal","TextColors","@text_colors");
system("defaults","write","com.apple.terminal","TerminalOpaqueness","$opaqueness");
[/code]



[ Reply to This | # ]
zeorge finally :) a super script
Authored by: uurf on Aug 27, '04 04:28:00PM

it doesn't like something here:


-bash: /Users/shortname/.bashrc: line 20: syntax error near unexpected token `('
-bash: /Users/shortname/.bashrc: line 20: `@color_table = ( "0.200 0.000 0.000","0.000 0.200 0.000","0.000 0.000 0.200" );'



[ Reply to This | # ]
you cant just copy paste this into your bashrc
Authored by: zeorge on Aug 29, '04 06:57:41AM

you cant just copy paste this into your bashrc...

this is a PERL script. your bashrc is a SHELL script.
(see the first line #!/usr/bin/perl - which is important!)

you must save the script as a file, do a "chmod +x file",
and then you can call it with "file" from your bashrc
zeo



[ Reply to This | # ]
zeorge finally :) a super script
Authored by: mysty on Sep 10, '04 03:39:05PM

Thanks for all these tips

In trying to get this going (10.3 with bash) I made a .bashrc with

. ~/scripts/termcolours.pl

as the first line and did the chmod+x on the above .pl file. Now when I launch a new Terminal window I get

-bash: /Users/me/scripts/termcolours.pl: line 5: syntax error near unexpected token `('
-bash: /Users/mye/scripts/termcolours.pl: line 5: ` @color_table = ( "0.200 0.000 0.000","0.000 0.200 0.000","0.000 0.000 0.200" );'

I think I got perl581 going on (according to Fink at least), so I cant get why Im getting this error.
Any ideas are most welcome. The wierd thing is that I am getting a similar error on line 5 of tim1724's script below as well...

As well as this wierd new .bashrc.swp file, and this console msg:

2004-09-10 19:19:01.779 Safari[2097] (goo, "bashrc.swp")

wtf?! goo?!? *boggle*

I havent relaunched Terminal yet as I was fink updating nmap and it wanted me to reinstall xfree86-base again (......)

TIA for your thoughts



[ Reply to This | # ]
zeorge finally :) a super script
Authored by: raider on Oct 29, '04 10:00:16AM
I combined Slur's and Zorge's scripts. I wanted the randomness of Slur's, but the speed of Zeorge's. Here is what I came up with:

#!/usr/bin/perl
$r = int(rand(2000));
$g = int(rand(2000));
$b = int(rand(2000));
$opaqueness = "0.98";
@text_colors = split " ",`defaults read com.apple.terminal TextColors`;
$pos = 1 ;
@text_colors[$pos*3] = ".$r";
@text_colors[$pos*3+1] = ".$g";
@text_colors[$pos*3+2] = ".$b";
$pos = 4 ;
@text_colors[$pos*3] = ".$r";
@text_colors[$pos*3+1] = ".$g";
@text_colors[$pos*3+2] = ".$b";
system("defaults","write","com.apple.terminal","TextColors","@text_colors");
system("defaults","write","com.apple.terminal","TerminalOpaqueness","$opaqueness");


Works pretty good, but every now and then I get a pretty bac random color... ;) Anyone who can improve the random generation ranges feel free to chime in....

[ Reply to This | # ]