使用AppleScript从safari中的Web Inspector复制文本

使用AppleScript从safari中的Web Inspector复制文本,safari,applescript,Safari,Applescript,我必须从Safari的web检查器复制并粘贴代码。目前,我使用的代码是: tell application "System Events" tell process "Safari" set frontmost to true click menu item "Show Web Inspector" of menu "Develop" of menu bar 1 -- click menu item "Select All" of

我必须从Safari的web检查器复制并粘贴代码。目前,我使用的代码是:

tell application "System Events"
    tell process "Safari"
        set frontmost to true
        click menu item "Show Web Inspector" of menu "Develop" of menu bar 1
        --      click menu item "Select All" of menu "Edit" of menu bar 1
        click menu item "Copy" of menu "Edit" of menu bar 1
        delay 1
    end tell

end tell

set desktopPath to (path to desktop as text)

tell application "TextEdit"
    activate
    set newDoc to (make new document with properties {text:(the clipboard)})
    save newDoc in file (desktopPath & (name of newDoc) & ".html")
end tell
但这段代码的问题是,它不是从web inspector复制内容,而是从页面复制文本内容。或者在某些情况下,剪贴板没有被修改。我怎样才能完成这项工作


我是一个初学者;D

为了解决您的问题,我会使用键盘大师,而不是执行“编辑>全选”,我会告诉键盘大师按“Cmd+A”

我会在事件之间放置一些适当的
延迟
命令。这样,Web检查器就有时间打开并复制焦点。但是为什么不将页面保存为
格式:页面源代码
?是的,我可以直接保存页面源代码。但是,我们的目标是解决这个问题,就像准备考试一样好的,我通常不会帮助用户完成作业,但是,当Web Inspector第一次打开“元素”选项卡时,它通常会打开最后一个选定的选项卡,因此,您可能也需要考虑到这一点。有时,在更全面的回答中包括澄清OP要求的问题是合适的。但你绝对不应该把新问题作为答案的一部分。相反,提出一个答案,然后,如果您无法找到解决堆栈溢出问题的方法,请将其作为新问题发布。