A newbie at Applescript here. I'm trying to make a script that scans text in a text editor online and replaces words with other words.
In my specific case, it's replacing a few html snippets with nothing "" — i.e. deleting them.
My current script gets the following error message… "Brave Browser got an error: window 1 doesn’t understand the “execute” message." number -1708 from window 1
Here's the script below. The line that is problematic seems to be where the EditorField variable comes in.
Any pointers or ideas out there to get this working? Thanks.
tell application "Brave Browser"
activate
my replaceWordWithStringInBodyText(" ", "")
my replaceWordWithStringInBodyText("<span class=\"Apple-converted-space\">", "")
my replaceWordWithStringInBodyText("<b>", "<strong>")
end tell
on replaceWordWithStringInBodyText(searchWord, replacementString)
tell application "Brave Browser"
activate
tell window 1
set EditorField to (execute javascript "document.getElementById('\"wp-content-editor-container\"')")
tell EditorField
-- start at the end and go to the beginning
repeat with i from the (count of paragraphs) to 1 by -1
tell paragraph i
repeat
try
if exists searchWord then
set (last word where it is searchWord) to replacementString
else
exit repeat
end if
on error errorMessage
exit repeat
end try
end repeat
end tell
end repeat
end tell
end tell
return true
end tell
end replaceWordWithStringInBodyText
('\"wp-content-editor-container\"')to('wp-content-editor-container')as there is no need to use escaped double-quotes inside of the single-quotes. Additionally, it's always a good idea to include the URL of the target page, assuming it's accessible to everyone, so we can test the code against the same as you. - user3439894