Created
March 10, 2014 16:48
-
-
Save 0x4a/9468847 to your computer and use it in GitHub Desktop.
takes a rrggbb hex #color number from #clipboard and pastes it to standard windows color selector as three dec numbers #ahk #work #tool
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
#NoEnv | |
#SingleInstance, Force | |
#Warn | |
SendMode Input | |
OnExit, ExitSub | |
; takes a rrggbb hex number from clipboard and pastes it to standard | |
; windows color selector as three dec numbers | |
; pick colors | |
; convert hue/saturation/value, rgb(dec), rgb(hex), windows colorpicker | |
; x:\Eigene Dateien\Dropbox\Backup\ahk-collection.7z\collection\Tools\WhatColor.ahk | |
; x:\Eigene Dateien\Dropbox\Backup\ahk-collection.7z\collection\Tools\rgb_conv.ahk | |
init() | |
{ | |
global | |
DEBUG = true | |
itemsLog = 0 | |
linesLog = 1 | |
debugLogFile := A_ScriptDir "\" SubStr( A_ScriptName, 1, -3 ) . "log" | |
debugLogNewline = false | |
; check logs | |
local lastTime, compare := "" | |
FileGetTime, lastTime, %debugLogFile% | |
EnvSub, lastTime, , hours | |
if(Abs(lastTime) > 12) | |
{ | |
local file := FileOpen(debugLogFile, "a") | |
if !IsObject(file) | |
{ | |
MsgBox Can't open "%debugLogFile%" for writing | |
return | |
} | |
file.Write("`n`n[" . A_Now . "]`n") | |
debugLogNewLine := true | |
file.Close() | |
} | |
} | |
init() | |
Loop { | |
; ctrl + shift + v | |
+^v::convertColorString(clipboard) | |
} | |
convertColorString(colorString) | |
{ | |
userMessage("lorem ipsum",, "d", "m", "t") | |
hexString := checkString(colorString) | |
if (hexString) | |
cursorMessage("valid: " . hexString) | |
;makeObject(hexColor) | |
;insertColor() | |
} | |
checkString(colorString) | |
{ | |
shortString := SubStr(colorString,1,10) | |
writeLog("Clipboard Contents: """ . shortString . """") | |
; no oversized strings | |
if (StrLen(colorString) > 7) | |
{ | |
wrongFormat("wrong length: " . StrLen(colorString)) | |
return 0 | |
} | |
; formating | |
StringLower, colorString, colorString | |
colorString := trimHash(colorString) | |
; check string length | |
if (StrLen(colorString) != 6 and StrLen(colorString) != 3) ; only length of 3 and 6 are valid | |
{ | |
wrongFormat("wrong length: " . StrLen(colorString)) | |
return 0 | |
} | |
; check hex format | |
i = 0 | |
Loop, Parse, colorString | |
{ | |
loopDigit = 0x%A_LoopField% | |
if loopDigit is not integer | |
{ | |
wrongFormat("digit " . A_Index . " not in range: " . A_LoopField) | |
return 0 | |
} | |
i++ | |
} | |
writeLog("all " . i . " digits seem to be valid hex") | |
return colorString | |
} | |
trimHash(colorString) | |
{ | |
; check for #-prefix and trim it | |
isTrimmed = false | |
if (StrLen(colorString) = 7 or StrLen(colorString) = 4) ; length = 7 or 4 | |
{ | |
if (SubStr(colorString,1,1) = Chr(35)) ; first char is # | |
{ | |
StringTrimLeft, colorString, colorString, 1 ; delete first char | |
isTrimmed = true | |
} | |
} | |
if (isTrimmed == true) ; debug info | |
writeLog("trimmed: " . colorString) | |
return colorString | |
} | |
; error message | |
wrongFormat(errorText) | |
{ | |
errorMessage := "invalid string - " . errorText | |
writeLog(errorMessage) | |
cursorMessage(errorMessage, 2000) | |
writeLog("restarting...`n") | |
global debugLogNewLine = true | |
return | |
} | |
userMessage(string, duration = 750, select*) | |
{ | |
sendT = false | |
sendM = false | |
sendS = false | |
sendD = false | |
out := "" | |
in := "" | |
for index, element in select | |
{ | |
ifEqual, element, "t" | |
sendT = true | |
ifEqual, element, "m" | |
sendM = true | |
ifEqual, element, "s" | |
sendS = true | |
ifEqual, element, "d" | |
sendD = true | |
in .= element | |
} | |
out := "" | |
if (sendM) | |
out .= " M " | |
if (sendT) | |
out .= " T " | |
if (sendS) | |
out .= " S " | |
if (sendD) | |
out .= " D " | |
Msgbox, %out% . %in% | |
/* message channels | |
* | |
* tooltip - 3 | |
* messagebox - 5 | |
* splashtext - 7 | |
* debug-log - 11 | |
* | |
* | |
*/ | |
cursorMessage(string, duration) | |
;msgbox,48,Error!,%string%,%duration% | |
splashMessage(string, duration) | |
;writeLog(string) | |
return | |
} | |
cursorMessage(string, time = 750) | |
{ | |
SetTimer, cursorTime, %time% | |
Tooltip, %string% | |
return | |
} | |
splashMessage(string, time = 750) | |
{ | |
SetTimer, splashTime, %time% | |
SplashTextOn,500,250, Error!, %string% | |
return | |
} | |
; DEBUG LOGS | |
writeLog(entry) | |
{ | |
global debugLogFile, debugLogNewLine | |
file := FileOpen(debugLogFile, "a") | |
if !IsObject(file) | |
{ | |
MsgBox Can't open "%debugLogFile%" for writing | |
return | |
} | |
if (debugLogNewLine) | |
{ | |
file.Write(entry) | |
debugLogNewLine := false | |
} | |
else | |
{ | |
file.Write(" - " . entry) | |
} | |
file.Close() | |
global itemsLog += 1 | |
} | |
writeLogNewline(n = 1) | |
{ | |
if (n <= 0) | |
return | |
global debugLogFile, debugLogNewLine, linesLog | |
file := FileOpen(debugLogFile, "a") | |
if !IsObject(file) | |
{ | |
MsgBox Can't open "%debugLogFile%" for writing | |
return | |
} | |
Loop, n | |
{ | |
file.Write("`n") | |
linesLog += 1 | |
} | |
debugLogNewLine := true | |
file.Close() | |
} | |
; DEBUG LOGS | |
readLog() | |
{ | |
; check if already open | |
global debugLogFile | |
Run notepad.exe %debugLogFile% | |
; save to file, open in editor | |
} | |
; tooltip timer | |
cursorTime: | |
{ | |
SetTimer, cursorTime, off | |
Tooltip, | |
return | |
} | |
; splashtext timer | |
splashTime: | |
{ | |
SetTimer, splashTime, off | |
SplashTextOff | |
return | |
} | |
ExitSub: | |
{ | |
if (DEBUG) | |
{ | |
writeLog("`nExit: " . A_ExitReason . " --- " . linesLog . " new messages in the log.`n`n") | |
readLog() | |
} | |
ExitApp | |
} | |
/* | |
123456789012345678901234567890123456789012345678901234567890 | |
#123456 | |
#A0B1C2 | |
#rrggbb | |
#unsinn | |
1234567 | |
123456 | |
A0B1C2 | |
rrggbb | |
unsinn | |
#123 | |
#A0B | |
#RGB | |
#FOO | |
1234 | |
123 | |
A0B | |
FOO | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment