Just trying to target my ChatGPT window. I’m getting an error.
tell application “Google Chrome”
set windowName to “F4”
set clipboardText to the clipboard as text
repeat with w in windows
if title of w is windowName then
activate w
delay 0.5 – allow the window to fully activate
do JavaScript “document.querySelector(‘[data-placeholder="Message ChatGPT"]’).innerText = '” & clipboardText & “';” in w
exit repeat
end if
end repeat
end tell
daBee. I don’t have access to ChatGPT and can’t test your script. However, the following is a working example of a script with the correct syntax for JavaScript with Google Chrome:
set className to "testButton"
set classNumber to "0"
tell application "Google Chrome"
execute tab 1 of window 1 javascript "document.getElementsByClassName('" & className & "')[" & classNumber & "].click();"
end tell
I’d be careful about just putting single quotes around a block of text. What if that text has one or more single quotes in it? They need to be escaped. For shell commands, there is “quoted form of”, but for this you might need to make your own function.