A maybe stupid question on color values


(Andreas Kiel) #1

Up to now I thought RGBA forms of color would convert like {255,255,255,255} -> {1,1,1,1} - as example
Now I have some (from another app) which are {1, 1.2, 1,1} means some values are above 1.
How to handle?


(Mark Alldritt) #2

This all depends on how the application you are scripting handles colors. Can you give us a small snippet of AppleScript that illustrates the problem you are experiencing?


(Andreas Kiel) #3

Thanks for responding.
There is no real code yet. It’s just a question which came across while analysing XMLs and thinking about the best way to go from Satimage to “plain” ASobjC
so with the XMLs there are attributes defining the color:
<text-style font="Arial" fontSize="53" fontColor="1 1 1 1" bold="0" italic="0" alignment="center"></text-style>
This is white.
On other places in the XML color is defined as
color="0.9 1.112 0.75 1"
Or values like
<param name="Color" key="9999/24742/24746/5/24748/14/16" value="-0.172828 0.991439 1.00078"/>

Former way was just to multiply by 255 and round (to integer).


(Shane Stanley) #4

Have you read the Color and Color Spaces section of the documents for NSColor?

Some of the documentation about the color creation methods is wrong — several accept values above 1.0, and use extended color spaces in such cases.


(Andreas Kiel) #5

Thanks Shane,

I obviously missed that part

Some of its values will be outside of the 0-1.0 range.

That makes me feel like an “idiot” :wink:
But reading it again several times I haven’t found a way to handle:

Sorry for these dumb questions.


(Andreas Kiel) #6

Is there a way to list all available colorspaces?


(Shane Stanley) #7
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSRGBColorSpaceModel)