Copying the text from Web Inspector in safari using AppleScript

时间:2018-11-13 14:21:30

标签: safari applescript

I have to copy and paste the code from Safari's web inspector. For now, the code I am using is:

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

But the problem with this code is, instead of copying the content from web inspector, it's copying the text content from the page. Or in some cases, the clipboard isn't getting modified. How can I get the job done?

PS. I am a beginner ;D

1 个答案:

答案 0 :(得分:-2)

要解决您的问题,我将使用Keyboard maestro,而不是执行“ edit>全选”操作,而是告诉Keyboard maestro按“ Cmd + A”