Created
November 29, 2011 23:07
-
-
Save notch8-old/1407060 to your computer and use it in GitHub Desktop.
itermColor.applescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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