NSLevelIndicator: How can I change the color (Warning/critical value)?

Hi!
in an ASS application i have a level indicator.
In Interface Builder I can set a warning value and a critical value, which changes the color of the indicator from green to orange to red, if the value is lower.

How can I change the warning value and critical vale during runtime?
Or can I otherwise change the color of a level indicator?

thanks in advance, Spock

Hi Spock,

to set critical and warning values during runtime there is no AppleScript access - you have to use 'call method’s for this. Without having tried I’d say something like this should work:

call method “setWarningValue:” of your Level Indicator with parameter value you want to set
call method “setCriticalValue:” of your Level Indicator with parameter value you want to set

an ‘update’ might be necessary to show the changes.

Unfortunately the class has no method for changing/setting it’s colors. If you want this you’d have to this in a custom subclass of NSLevelIndicator.

D.

Thank you for your reply, but I can´t get it to work.

the AppleSkript name of my Level indicator is “speedRuler”, so I have tried

call method "setWarningValue:" of "speedRuler" with parameter 80

does not work

set temp to control "speedRuler" of window "main"
call method "setWarningValue:" of temp with parameter 80

does not work

I did change the content value of the control. Or did you mean something different, by “an ‘update’ might be necessary to show the changes.”

Do I have to add something to my project?

Hi spock,

I just tried it - updating the view isn’t necessary to have the changes displayed. Here’s what I tried - it works regardlessly here:

	tell control "speedRuler" of window "main"
		set contents to 89
		delay 1
		call method "setWarningValue:" of it with parameter 80
		delay 1
		call method "setCriticalValue:" of it with parameter 85
		delay 1
		set contents to 84
		delay 1
		set contents to 73
	end tell

Hope that helps,

Dominik

Thank you Dominik.
It works fine, as well as my first try

set temp to control "speedRuler" of window "main"
call method "setWarningValue:" of temp with parameter 80

works.
My problem was, that I duplicated a TestButton in InterfaceBuilder, and just gave it a name. I did not notice, that duplicating an object DOES NOT duplicate its EventHandlers and ScriptConnections. (Boy, i consider this to be a severe bug). So my TestButton2 did just nothing at all.

Thanks again for help!