#!/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); }

In reply to Dynamically Generating Mac OSX Terminal.app Colors by techy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.