Skip to content

Instantly share code, notes, and snippets.

@notch8-old
Created November 29, 2011 23:07
Show Gist options
  • Select an option

  • Save notch8-old/1407060 to your computer and use it in GitHub Desktop.

Select an option

Save notch8-old/1407060 to your computer and use it in GitHub Desktop.
itermColor.applescript
-- This nasty constant might as well be a global
global kColorValueMaximum
set kColorValueMaximum to 32767
-- Using only half the max of 65535
-- Choose a random color for the background
set randomRed to (random number) * kColorValueMaximum
set randomGreen to (random number) * kColorValueMaximum
set randomBlue to (random number) * kColorValueMaximum
set myBackgroundColor to {randomRed, randomGreen, randomBlue}
-- Select appropriate text colors based on that background
-- set {myTextColor, myBoldColor} to my ContrastingTextColors(myBackgroundColor)
-- Now inflict them on the frontmost window
tell application "iTerm"
set current_terminal to (current terminal)
tell current_terminal
set current_session to (current session)
tell current_session
set background color to myBackgroundColor
-- set cursor color to myTextColor
-- set foreground color to myTextColor
end tell
end tell
end tell
-- on ContrastingTextColors(myColor)
-- set whiteColor to {kColorValueMaximum, kColorValueMaximum, kColorValueMaximum, kColorValueMaximum}
-- set lightGreyColor to {40000, 40000, 40000, kColorValueMaximum}
-- set blackColor to {0, 0, 0, kColorValueMaximum}
-- set darkGreyColor to {20000, 20000, 20000, kColorValueMaximum}
--
-- -- From http://www.wilsonmar.com/1colors.htm
-- set myRed to (item 1 of myColor) / kColorValueMaximum
-- set myGreen to (item 2 of myColor) / kColorValueMaximum
-- set myBlue to (item 3 of myColor) / kColorValueMaximum
-- set magicY to (0.3 * myRed) + (0.59 * myGreen) + (0.11 * myBlue)
-- if (magicY < 0.5) then
-- return {whiteColor, lightGreyColor}
-- else
-- return {blackColor, darkGreyColor}
-- end if
-- end ContrastingTextColors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment