How many times would it be necessary to repeat that I can’t run Catalina on my machine.
So I was unable to guess which way to define colors are available in Reminders.
I asked you about that but you never answered (of course you weren’t forced to do that).
So don’t be surprised if I didn’t knew the answer.
Now, thanks to my grand daughter, I know that there is only a single scheme : a “palette” with 12 colored buttons.
We aren’t allowed to define the hexadecimal string describing a color, it’s a property of this one.
The script which I posted in message #11 extracted the colors in an application (“Numbers”) using two of the standard dedicated tools whose French names are :
{“Roue des couleurs”, “Curseurs de couleur”, “Palettes de couleurs”, “Palettes d’images”, “Crayons”, “RCWeb”}
From the palette “Crayons” I select a pencil, grab the name of the color (in fact its description).
Then I switch to the palette “RCWeb” which display the hexadecimal value describing the color as well as its three individual hexadecimal component : R(ed) G(reen) B(lue).
This morning I tried to achieve the same task without switching between palettes using the command do shell script “/usr/local/bin/cliclick cp:” & xCB + wCB div 2 & “,” & yCB + hCB div 2
supposed to return the three individual components as decimal strings.
----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
-- Yvan KOENIG (VALLAURIS, France) lundi 27 avril 2020 20:56:05
----------------------------------------------------------------
property |⌘| : a reference to current application
set reportName to "the_colors Cliclick.txt"
set targetFile to (path to desktop as string) & reportName
tell application "Numbers"
activate
tell document 1 to tell sheet 1 to tell table 1
set selection range to range "B2"
end tell
end tell
tell application "System Events" to tell process "Numbers"
set frontmost to true
set mainWindow to first window whose subrole is "AXStandardWindow"
tell mainWindow
-- class of UI elements --> {scroll area, button, scroll area, button, button, scroll area, button, button, radio group, scroll area, button, button, button, menu button, toolbar, tab, static text, static text}
tell radio group 1
-- class of UI elements --> {radio button, radio button, radio button, radio button}
-- name of radio buttons --> {"Tableau", "Cellule", "Texte", "Disposition"}
click radio button 2 --> "Cellule"
end tell
(*
tell scroll area 1
class of UI elements --> {scroll bar, scroll bar}
end tell
tell scroll area 2
class of UI elements --> {static text}
value of static text 1 --> "Feuille 1"
end tell
tell scroll area 3
class of UI elements --> --> {static text, static text}
value of static texts --> {"", ""}
end tell
*)
tell scroll area 4
-- class of UI elements --> {pop up button, static text, UI element, static text, button, pop up button, static text, image, list, color well, text field, incrementor, pop up button, menu button, button, scroll bar}
-- help of pop up buttons --> {"Choisissez le format d’affichage des valeurs dans les cellules sélectionnées. ", "Choisissez un type de remplissage.", missing value}
-- title of buttons--> {"", "Surlignage conditionnel…"}
set {{xCB, yCB}, {wCB, hCB}} to {position, size} of button 1 -- the one displaying the fill color
tell pop up button 2
click it
tell menu 1
-- get name of menu items --> {"Aucun", "Remplissage couleur", "Remplissage dégradé", "Remplissage dégradé avancé", "Remplissage par image", "Remplissage image avancé"}
click menu item 2 --> "Remplissage couleur"
end tell
end tell -- pop up button 2
set {{xCW, yCW}, {wCW, hCW}} to {position, size} of color well 1
end tell -- scroll area 4
end tell -- mainWindow
repeat 10 times
delay 0.2
if exists (first window whose subrole is "AXFloatingWindow") then exit repeat
-- Click in the square at right edge of the color wheel
tell me to do shell script "/usr/local/bin/cliclick c:" & (xCW + wCW) - (hCW div 2) & "," & yCW + hCW div 2
end repeat
set floatingWindow to first window whose subrole is "AXFloatingWindow"
set nbRadioButtons to 48
set descriptors to {}
repeat with i from 1 to nbRadioButtons
tell floatingWindow
-- class of UI elements --> {splitter group, button, button, button, toolbar, static text}
tell toolbar 1
-- class of UI elements --> {button, button, button, button, button, button}
-- description of buttons --> {"Roue des couleurs", "Curseurs de couleur", "Palettes de couleurs", "Palettes d’images", "Crayons", "RCWeb"}
click button -2 -- Crayons
end tell -- toolbar 1
tell splitter group 1
-- class of UI elements --> {static text, radio group, slider, static text, text field, splitter, color well, checkbox, scroll area}
tell radio group 1
-- class of UI elements --> {radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button, radio button}
set itsName to accessibility description of radio button i --> the local name of the color
-- Grab position and size of the radio button ( a pencil )
set {{xC, yC}, {wC, hC}} to {position, size} of radio button i
tell me
-- Really Click it
do shell script "/usr/local/bin/cliclick c:" & xC + wC div 2 & "," & yC + hC div 2
-- Peek the color in the ill Color (the color is not the same in every point of the pencil)
set theColors to do shell script "/usr/local/bin/cliclick cp:" & xCB + wCB div 2 & "," & yCB + hCB div 2
end tell
end tell
end tell -- splitter group 1
set RGB to ""
repeat with v in my decoupe(theColors, space)
set RGB to RGB & my num2hex(v as integer)
end repeat
set end of descriptors to itsName & tab & "#" & RGB
end tell -- mainWindow
end repeat
end tell -- System Events
my writeArray:descriptors inFile:targetFile
tell application "TextEdit"
activate
if exists window reportName then close window reportName
open targetFile
end tell
#=====
on writeArray:anArray inFile:hfsPath
set anArray to |⌘|'s NSArray's arrayWithArray:anArray
set theData to (anArray's componentsJoinedByString:linefeed)
-- save data to new file
(theData's writeToURL:(hfsPath as «class furl») atomically:true encoding:(|⌘|'s NSUTF8StringEncoding) |error|:(missing value))
end writeArray:inFile:
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
on num2hex(t)
set hi to t div 16
set lo to t mod 16
return (text item (hi + 1) of "0123456789ABCDEF") & (text item (lo + 1) of "0123456789ABCDEF")
end num2hex
#=====
The manual of Cliclick states:
cp:str Will PRINT THE COLOR value at the given screen location.
The color value is printed as three decimal 8-bit values,
representing, in order, red, green, and blue.
Example: “cp:123,456” might print “127 63 0”
Alas the returned values aren’t identical to those returned by the palette delivered by Apple.
Is it clear now ?
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 29 avril 2020 14:55:39