| — 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
–Crayon Picker Color Data
 set crayonPickerList to {{0, 0, 0}, {6425, 6425, 6425}, {13107, 13107, 13107}, {19532, 19532, 19532}, {26214, 26214, 26214}, {32639, 32639, 32639}, {32896, 32896, 32896}, {39321, 39321, 39321}, {46003, 46003, 46003}, {52428, 52428, 52428}, {59110, 59110, 59110}, {65535, 65535, 65535}, ¬
 {32896, 0, 0}, {32896, 16448, 0}, {32896, 32896, 0}, {16448, 32896, 0}, {0, 32896, 0}, {0, 32896, 16448}, {0, 32896, 32896}, {0, 16448, 32896}, {0, 0, 32896}, {16448, 0, 32896}, {32896, 0, 32896}, {32896, 0, 16448}, ¬
 {65535, 0, 0}, {65535, 32896, 0}, {65535, 65535, 0}, {32896, 65535, 0}, {0, 65535, 0}, {0, 65535, 32896}, {0, 65535, 65535}, {0, 32896, 65535}, {0, 0, 65535}, {32896, 0, 65535}, {65535, 0, 65535}, {65535, 0, 32896}, ¬
 {65535, 26214, 26214}, {65535, 52428, 26214}, {65535, 65535, 26214}, {52428, 65535, 26214}, {26214, 65535, 26214}, {26214, 65535, 52428}, {26214, 65535, 65535}, {26214, 52428, 65535}, {26214, 26214, 65535}, {52428, 26214, 65535}, {65535, 26214, 65535}, {65535, 28527, 53199} ¬
 }
 tell application "Keynote"
 activate
 set newDoc to make new document with properties {document theme:theme "ホワイト"} — theme name is *Localized*. This is "White" in Japanese
 
 tell window 1
 –set {x1, y1, x2, y2} to bounds
 
 set bounds to {0, 0, 1500, 900}
 end tell
 
 tell newDoc
 set blankSlide to master slide "空白" –master slide name is *Localized*. This is "Blank" in Japanese
 
 tell slide 1
 set base slide to blankSlide
 
 delete every table
 set tRes to make new table
 
 tell tRes
 set row count to 12
 set column count to 8
 set background color of every cell to {65535, 65535, 65535}
 set header column count to 0
 set header row count to 0
 set footer row count to 0
 
 repeat with i from 0 to (length of crayonPickerList) – 1
 set a1Num to (i mod 12) + 1
 set b1Num to ((i div 12) + 1) * 2 – 1
 set b2Num to b1Num + 1
 set aCol to contents of item (i + 1) of crayonPickerList
 
 tell column b1Num
 tell cell a1Num
 ignoring application responses
 set background color to aCol
 end ignoring
 end tell
 end tell
 
 —————————————————————————————————–
 copy aCol to {rCol, gCol, bCol}
 set aColor to makeNSColorFromRGBAval(rCol, gCol, bCol, 65535, 65535) of me
 set cdnStr to retColorIsRedOrBlueFromNSColor(aColor) of me –red, blue, other
 —————————————————————————————————–
 
 if cdnStr = "red" then
 set textCol to {65535, 0, 0}
 else if cdnStr = "blue" then
 set textCol to {0, 0, 65535}
 else
 set textCol to {0, 0, 0}
 end if
 
 tell column b2Num
 tell cell a1Num
 ignoring application responses
 set value to cdnStr
 set text color to textCol
 end ignoring
 end tell
 end tell
 
 end repeat
 
 end tell
 
 end tell
 end tell
 
 end tell
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
 |