TheOnlyOneHere
TheOnlyOneHere

Reputation: 123

How to change color text of Button with AppleScript?

Is there a way to change the color of a button's text when it is selected?

I tried something like:

property myButton : missing value

myButton's setTintColor:(current application's NSColor's cyanColor)

But I get the error below:

-[NSButton setTintColor:]: unrecognized selector sent to instance 0x7fc865f2d000 (error -10000)

Upvotes: 0

Views: 278

Answers (1)

red_menace
red_menace

Reputation: 3412

To apply attributes such as color to button titles, you can use an NSAttributedString, for example:

    set buttonTitle to myButton's title -- get current title
    set attrString to current application's NSMutableAttributedString's alloc's initWithString:buttonTitle
    attrString's addAttribute:(current application's NSForegroundColorAttributeName) value:(current application's NSColor's cyanColor) range:{0, buttonTitle's |length|}
    set myButton's attributedTitle to attrString

Upvotes: 1

Related Questions