bobsmith76
bobsmith76

Reputation: 292

input value into Safari using Applescript

I'm trying to input a value into a Safari webpage, this one to be exact

http://rapidtables.com/web/color/RGB_Color.htm

using apple script. I'm able to get the apple script to read the value in one of the input boxes but I can't get apple script to put a value into the boxes. This is what I'm trying.

activate application "Safari"
tell application "System Events"
    tell process "Safari"

        tell text field 1 of group 1 of group 4 of group 4 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "RGB Color Codes Chart"
            set value to 130
        end tell
    end tell
end tell

Upvotes: 1

Views: 866

Answers (1)

Jerry Stratton
Jerry Stratton

Reputation: 3456

Text fields require strings; even though the field is “asking for” a number, it’s really a string of text behind the scenes.

Replace 130 with "130" and your script works. I’ve verified that this is the only change necessary to make the “R” value on that web page change from 255 (or whatever its current value is) to 130.

If your actual script will be setting the value of the text field to the value of a numeric variable rather than a hard-coded value as in your example, you’ll need to convert that numeric variable to a string. For example:

activate application "Safari"
--this is a numeric variable
set rValue to 131

tell application "System Events"
    tell process "Safari"

        tell text field 1 of group 1 of group 4 of group 4 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "RGB Color Codes Chart"
            --the numeric value must be coerced to a string value
            set value to rValue as string
        end tell
    end tell
end tell

Upvotes: 2

Related Questions