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


Click here to return to the 'A slightly nicer & prettier script...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A slightly nicer & prettier script...
Authored by: dbs on Aug 26, '04 06:41:39PM
Here is a slightly nicer AppleScript to do this. It allows you to have either white-on-color or color-on-white windows, or randomly select them. It sets the value and saturation appropriately for either setting and then randomly selects the hue. This dramatically reduces the number of ugly colors you get. To force it to always choose white on black or vice versa simply change the
random_select_white_on_black
property to false and set the other to whatever you want. To run it do the same as above by calling the apple script from a command line. I use a script called color which has:

#!/bin/sh
exec osascript "$HOME/Library/Scripts/Better Random Terminal Color.scpt"
Then I call it from my .cshrc if I am running Apple's Terminal Program by putting this in the file:

# Set a random terminal color
if ($?TERM_PROGRAM) then
    if ($TERM_PROGRAM == "Apple_Terminal") then
        $HOME/bin/color
        setenv TERM xterm-color
    endif
endif
The Apple Script is:

property transparency : 65535
property dark_saturation : 1.0
property dark_value : 0.3
property light_saturation : 0.1
property light_value : 0.9
-- Enable to randomly select if you want white on black or black on white text
property random_select_white_on_black : true
-- If it is not random this controls which color scheme you get
property white_on_black : true

-- Based on http://www.cs.rit.edu/~ncs/color/t_convert.html
-- Note that there is an error on that page with regards to f
on HSVtoRGB(h, s, v)
	--log "HSBtoRGB: h:" & h & " v:" & v & " s:" & s
	-- h in degrees
	-- s in 0 to 1.0
	-- v in 0 to 1.0
	
	if s = 0 then
		-- Gray, so set it accordingly
		set r to v
		set g to v
		set b to v
	else
		set sector to h / 60 -- sector for the hue
		set i to round (sector) rounding down
		set f to (h - i) / 360 -- remaining bit of h
		set p to v * (1 - s)
		set q to v * (1 - s * f)
		set t to v * (1 - s * (1 - f))
		
		if i = 0 then
			set r to v
			set g to t
			set b to p
		else if i = 1 then
			set r to q
			set g to v
			set b to p
		else if i = 2 then
			set r to p
			set g to v
			set b to t
		else if i = 3 then
			set r to p
			set g to q
			set b to v
		else if i = 4 then
			set r to t
			set g to p
			set b to v
		else
			set r to v
			set g to p
			set b to q
		end if
		
	end if
	
	--log "HSV2RGB - R: " & r & " G: " & g & " B: " & b
	
	set rgb to {r * 65535, g * 65535, b * 65535}
end HSVtoRGB


tell application "Terminal"
	set h to (random number 360)
	
	-- If we want to randomly choose between white and black text pick one
	if random_select_white_on_black is true then
		if (random number 1) > 0.5 then
			set white_on_black to true
		else
			set white_on_black to false
		end if
	end if
	-- Otherwise use the default above
	
	if white_on_black is false then
		-- Set to random color and black text..	
		tell window 1 to set background color to ((my HSVtoRGB(h, light_saturation, light_value)) & transparency)
		tell window 1 to set normal text color to ({0, 0, 0})
	else
		-- set to random color and white text/bold
		tell window 1 to set background color to ((my HSVtoRGB(h, dark_saturation, dark_value)) & transparency)
		tell window 1 to set normal text color to ({55000, 55000, 55000})
		tell window 1 to set bold text color to ({65535, 65535, 65535})
	end if
end tell
Enjoy! (And thanks to the others for the ideas!)

[ Reply to This | # ]