使用Applescript将值输入Safari

使用Applescript将值输入Safari,safari,applescript,Safari,Applescript,我试图在Safari网页中输入一个值,确切地说,这是一个 使用苹果脚本。我可以让apple脚本读取其中一个输入框中的值,但无法让apple脚本将值放入框中。这就是我正在尝试的 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 elemen

我试图在Safari网页中输入一个值,确切地说,这是一个

使用苹果脚本。我可以让apple脚本读取其中一个输入框中的值,但无法让apple脚本将值放入框中。这就是我正在尝试的

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

文本字段需要字符串;即使字段“要求”一个数字,它实际上是幕后的一系列文本

130
替换为
“130”
,您的脚本就可以工作了。我已经验证过,这是使该网页上的“R”值从255(或其当前值)更改为130所需的唯一更改

如果实际脚本将文本字段的值设置为数值变量的值,而不是像示例中那样的硬编码值,则需要将该数值变量转换为字符串。例如:

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