为什么在Safari中重新加载所有选项卡时,此AppleScript出现语法错误?

为什么在Safari中重新加载所有选项卡时,此AppleScript出现语法错误?,safari,tabs,applescript,reload,Safari,Tabs,Applescript,Reload,以下脚本出现错误,我复制该脚本以在Safari会话中重新加载所有选项卡 tell application "Safari" set a to tabs of the front window repeat with x in a set docUrl to URL of x set URL of x to docUrl end repeat end tell 错误消息是“Safari出错:无法将缺少的值转换为文本类型。” 错误出现在“将x

以下脚本出现错误,我复制该脚本以在Safari会话中重新加载所有选项卡

tell application "Safari"
    set a to tabs of the front window
    repeat with x in a
        set docUrl to URL of x
        set URL of x to docUrl
    end repeat
end tell
错误消息是“Safari出错:无法将缺少的值转换为文本类型。”

错误出现在“将x的URL设置为docUrl”行

这是我第一次尝试用AppleScript编写代码,所以请原谅我的错误


提前感谢。

可能是选项卡的
URL
属性返回了
缺少的值
,尽管选项卡显示了有效的数据

重新加载所有选项卡的更可靠的方法是JavaScript行

tell application "Safari"
    set allTabs to tabs of the front window
    repeat with aTab in allTabs
        tell aTab to do JavaScript "location.reload();"
    end repeat
end tell

如果您有多个打开了多个选项卡的窗口,这将起作用。这对我使用最新版本的macOS Mojave很有效

tell application "Safari"
    set theTabs to every document
    repeat with eachTab in theTabs
        tell eachTab to set URL to (get URL)
    end repeat
end tell

谢谢瓦迪安-我会尝试一下,然后再报告。感谢您的帮助。最好指出,这需要在Safari中的“开发”菜单上选中“允许来自Apple Events的JavaScript”菜单项,默认情况下该菜单是隐藏的。谢谢您的帮助-我会尝试一下