How do I convert a CYMK color space to RGB now that I’ve got the color returning OK? The following doesn’t work, but I don’t know enough to understand why.
Thanks in advance
Santa
set ThetempColor to ThetempColor's colorSpaceCreateWithName's colorSpaceGenericRGB
This is the text from the Developer notes, but everything I’ve tried to convert to Applescript ObjC has failed.
Can anyone offer a conversion please?
Regards
Santa
Can I Access the Components of Any NSColor Object?
It is invalid to use an accessor method related to components of a particular color space on an NSColor object that is not in that color space. For example, NSColor methods such as redComponent and getRed:green:blue:alpha: work on color objects in the calibrated and device RGB color spaces. If you send such a message to an NSColor object in the CMYK color space, an exception is raised.
If you have an NSColor object in an unknown color space and you want to extract its components, you should first convert the color object to a known color space before using the component accessor methods of that color space. For example:
NSColor *aColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
if (aColor) {
float rcomp = [aColor redComponent];
}
If the color is already in the requested color space, you get back the original object.
on colorWellSet_(sender)
try
set ThetempColor to theMainColorWell's |color|
--set ThetempColor to |color| of ThetempColor's colorUsingColorSpaceName_calibratedRGBColorSpace
log 1
log
set ThetempColor to theMainColorWell's colorUsingColorSpaceName_NSCalibratedRGBColorSpace
log 2
log
set ThetempColor to |color| of theMainColorWell's colorUsingColorSpaceName_NSCalibratedRGBColorSpace
log 3
log
set ThetempColor to ThetempColor's colorUsingColorSpaceName_NSCalibratedRGBColorSpace
--set ThetempColor to theMainColorWell's colorSpaceCreateWith_colorSpaceGenericRGB
set temp1 to ThetempColor's redComponent()
set temp2 to ThetempColor's greenComponent()
set temp3 to ThetempColor's blueComponent()
set TheColor to {(temp1 * 65535), (temp2 * 65535), (temp3 * 65535)}
on error errmsg
display dialog errmsg
end try
end colorWellSet_
returns logs in every case of…
17/11/09 10:45:29 AM Mail Manager Reporter[966] <Mail_Manager_ReporterAppDelegate @0x2007d6040: OSAID(4)>
17/11/09 10:45:29 AM Mail Manager Reporter[966] [<NSColorWell 0x2007ae6a0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key colorUsingColorSpaceName_NSCalibratedRGBColorSpace.
What am I doing wrong please, I’m getting worn out here!
The first line works fine. The problem is that the use can p ick a CMYK value, which crashes the script.
It’s obvious from the error messages that key values are needed, but reading up on them is like so much goblygook to me. I need an ASOC example to understand what to do.
I’ve altered the variable names, but that makes no difference.
I’m hoping someone will fix it, but things don’t look to good.
Answered by red menace and Hiroto from the Apple Discussions.
I first needed to declare a class.
property NSColor : class "NSColor"
then the script became…
on colorWellSet_(sender)
try
set ThetempColor to theMainColorWell's |color|
set ThetempColor to ThetempColor's colorUsingColorSpaceName_(current application's NSCalibratedRGBColorSpace)
set temp1 to ThetempColor's redComponent()
set temp2 to ThetempColor's greenComponent()
set temp3 to ThetempColor's blueComponent()
set TheColor to {(temp1 * 65535), (temp2 * 65535), (temp3 * 65535)}
on error errmsg
display dialog errmsg
end try
end colorWellSet_