【发布时间】:2020-02-26 03:50:27
【问题描述】:
这里是 Applescript 的新手。我正在尝试制作一个脚本,可以在线扫描文本编辑器中的文本并用其他词替换单词。
在我的具体情况下,它用 "" 替换了一些 html sn-ps — 即删除它们。
我当前的脚本收到以下错误消息... “Brave Browser 出现错误:窗口 1 不理解“执行”消息。”来自窗口 1 的数字 -1708
这是下面的脚本。有问题的行似乎是 EditorField 变量的来源。
有什么建议或想法可以让它发挥作用吗?谢谢。
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\"')更改为('wp-content-editor-container')因为不需要在单引号内使用转义的双引号.此外,包含目标页面的 URL 始终是一个好主意,假设每个人都可以访问它,这样我们就可以针对与您相同的 代码 进行测试。跨度>