指定の色が赤系統か青系統かその他かを判定するAppleScriptです。
パラメータをRTFから取得するプログラムで、テキストを青、データベースから取得して差し込む値を赤、コメント類を黒などで記述するようにしてみたため、赤/青/その他を判定するプログラムを作成してみました。
AppleScript名:色が赤系統か青系統かを判定する |
— Created 2018-02-27 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property NSColor : a reference to current application’s NSColor set {rCol, gCol, bCol} to choose color set aColor to makeNSColorFromRGBAval(rCol, gCol, bCol, 65535, 65535) of me –Detect the color is red or blue (or other) set cdnStr to retColorIsRedOrBlueFromNSColor(aColor) of me –> "red" / "blue" / "ohter" on retColorIsRedOrBlueFromNSColor(aColor) set aColDomain to retColorDomainNameFromNSColor(aColor) of me if aColDomain is in {"magenta", "purple", "orange", "red"} then return "red" else if aColDomain is in {"green", "cyan", "blue"} then return "blue" else return "other" end if end retColorIsRedOrBlueFromNSColor on retColorDomainNameFromNSColor(aCol) set hueVal to aCol’s hueComponent() set satVal to aCol’s saturationComponent() set brightVal to aCol’s brightnessComponent() if satVal ≤ 0.01 then set satVal to 0.0 set colName to "" if satVal = 0.0 then if brightVal ≤ 0.2 then set colName to "black" else if (brightVal > 0.95) then set colName to "white" else set colName to "gray" end if else if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then set colName to "red" else if hueVal ≤ (45.0 / 360) then set colName to "orange" else if hueVal < (70.0 / 360) then set colName to "yellow" else if hueVal < (150.0 / 360) then set colName to "green" else if hueVal < (190.0 / 360) then set colName to "cyan" else if (hueVal < 250.0 / 360.0) then set colName to "blue" else if (hueVal < 290.0 / 360.0) then set colName to "purple" else set colName to "magenta" end if end if return colName end retColorDomainNameFromNSColor on makeNSColorFromRGBAval(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer, aMaxVal as integer) set aRedCocoa to (redValue / aMaxVal) as real set aGreenCocoa to (greenValue / aMaxVal) as real set aBlueCocoa to (blueValue / aMaxVal) as real set aAlphaCocoa to (alphaValue / aMaxVal) as real set aColor to NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa return aColor end makeNSColorFromRGBAval |
More from my site
(Visited 365 times, 1 visits today)