I have found a way, for at least some cases, to get results from methods that don’t return a result except through C pointer arguments.
An example is the NSColor method getRed:&redVal green:&greenVal blue:&blueVal alpha:&alphaVal that places the r, g, b, and alpha values of an NSColor in C pointer arguments. Here is a Cocoa implementation:
- (void)getRGBValues
{
CGFloat redVal, greenVal, blueVal, alphaVal;
NSColor *sampleColor = [NSColor purpleColor];
[sampleColor getRed:&redVal green:&greenVal blue:&blueVal alpha:&alphaVal];
NSLog(@"r=%f g=%f b=%f a=%f", redVal, greenVal, blueVal, alphaVal);
NSLog(@"%@", sampleColor);
}
The first NSLog returns: r=0.500000 g=0.000000 b=0.500000 a=1.000000
The second NSLog returns: NSCalibratedRGBColorSpace 0.5 0 0.5 1
Notice that the second NSLog includes the desired results without resorting to the getRed:&redVal green:&greenVal blue:&blueVal alpha:&alphaVal method call. One can take advantage of this “leakage” by parsing the NSLog output. The following handler is an ASObjC solution. It is assumed to be in an ASObjC applicaiton named “ColorGetter” (the actual application name should be used instead of this, so that grep can home in on the appropriate entry in the system log):
on getRGBValues()
set sampleColor to current application's NSColor's purpleColor
log sampleColor
tell paragraphs of (do shell script "" & ¬
"cat /var/log/system.log | " & ¬
"grep \"ColorGetter\" | " & ¬
"tail -1 | " & ¬
"sed -E 's/^.+ ([0-9.]+) +([0-9.]+) +([0-9.]+) +([0-9.]+) *$/\\1\\" & linefeed & "\\2\\" & linefeed & "\\3\\" & linefeed & "\\4/'") to ¬
set {redVal, greenVal, blueVal, alphaVal} to {(item 1) as real, (item 2) as real, (item 3) as real, (item 4) as real}
return "r=" & redVal & " g=" & greenVal & " b=" & blueVal & " a=" & alphaVal
end getRGBValues
Running getRGBValues() returns: "r=0.5 g=0.0 b=0.5 a=1.0
which is the desired result.
This is admittedly a hack for an otherwise desperate situation.