AppleScript and Numbers

Howdy fellow Apple comrades,


I'm putting together a Numbers script and am setting the background of some of the cells, but I can't for the life of me figure out the RGB numbers that they're asking for. I know it's a scale of 0 to 65535 but when I'm looking at color scales, most RGB go from 0 to 255, or other places give me the hex value. What scale is this? How can I assign the colors?

iMac (27-inch, Late 2013), OS X Yosemite (10.10.1)

Posted on Jun 29, 2015 12:35 PM

Reply
4 replies

Jun 29, 2015 4:22 PM in response to david.lski

Although the question has been answered, here is an AppleScript that you run separately. It allows you to pick a color, converts that to RGB16 triplet color, and its hex value too. I have added the ability to display this RGB16 and Hex value in a dialog. You can select/copy/paste right from the dialog.


Copy and paste the following into your AppleScript Editor, compile, run and test. Then save it initially as a text (*.applescript) file, and then separately as a clickable application to your desktop or dock.


I have placed the attribution link at the beginning of the script.


Code:


-- StefanK: http://macscripter.net/viewtopic.php?pid=95047


property hexList : "0123456789ABCDEF"


set defaultHex to "#FFFFFF"

set r to ""

set g to ""

set b to ""


if defaultHex starts with "#" then

try

set chosenColor to choose colordefault colorHex8toRGB16(defaultHex)

-- logchosenColor

set {r, g, b} to items of chosenColor

set rgb16Value to "{" & r & ", " & g & ", " & b & "}"

on error

return

end try


set hexValue to RBG16toHex8(chosenColor)

-- loghexValue


end if


display dialog "RGB 16: " & tab & rgb16Value & return & " Hex:" & tab & "#" & hexValue

return


to RBG16toHex8(AppleRGB16)

set hexString to ""

repeat with primary in AppleRGB16

set hexString to hexString & character (primary div 4096 + 1) of hexList & character (primary div 256 mod 16 + 1) of hexList

end repeat

return hexString

end RBG16toHex8

--

to Hex8toRGB16(htmColor) -- format #xxxxxx

set RGB16 to {}

repeat with i from 2 to 6 by 2

set end of RGB16 to ((((offset of htmColor's character i in hexList) - 1) * 16) + (offset of htmColor's character (i + 1) in hexList) - 1) * 257

end repeat

return RGB16

end Hex8toRGB16

Jun 30, 2015 1:16 PM in response to david.lski

I'm lazy and don't like to do lots of math....🙂


So to get the rgb values that Numbers accepts via AppleScript I just use this in Script Editor:


set myRgb to choose color


After I've made my pick, I get a list in the Result pane that looks something like this: {64720, 17976, 19514}


Then (having addressed the document, sheet, and table as usual), I set the background color with a statement like this:


set cell "D3"'s background color to {64720, 17976, 19514}


And if I already have a Numbers cell prettied up with the background color I want, I select it and use this script like an "dropper" to capture the rgb values for use in scripts.


--get background color of a Numbers cell (if none returns 'missing value')

tell application "Numbers" to tell front document

set t to active sheet'stable 1 whose selection range'sclass is range

set bkgrRgb to t'sselection range'scell 1's background color


--> e.g. {64720, 17976, 19514}

end tell


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript and Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.