Using AppleScript to change text color in Keynote

In Keynote, if I select some text and run the following example AppleScript code, the color of the text is set to Blueberry:

activate application "Keynote"
tell application "System Events"
    tell application process "Keynote"
        tell window 1
            tell radio group of toolbar 1
                if value of radio button 1 = {{0}} then
                    click radio button 1
                end if
            end tell
            click color well of scroll area 1
            click button 5 of toolbar 1
            click radio button 33 of radio group 1 of splitter group 1
            click button 1
        end tell
    end tell
end tell

If you want to use the pencil color name instead of the radio button number, then change:

click radio button 33 of radio group 1 of splitter group 1

To:

click (every radio button of radio group 1 of splitter group 1 whose description is "Blueberry")

      Hint: Mouse over and horizontal scroll to see full code.

You can then substitute any valid pencil color for a different color then "Blueberry".

Note: The example AppleScript code was tested and worked, as is, on my Mac running macOS High Sierra and Keynote version 8.1 (5683).


Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.