在Applescript中获取Safari窗口的内容

时间:2011-09-01 11:16:38

标签: javascript safari applescript

我想获取Safari 5.1(Mac OS X)网页的内容,并使用Applescript将其粘贴到另一个应用程序中。

我使用AppleScript相对不错,但不是用JavaScript,假设答案在于JavaScript。

我可以使用系统事件来使用击键来选择全部然后复制...这很好用,但我有两个问题:

  1. 这很丑陋,当然必须有一种方法来编程。
  2. 我无法撤消我所做的全部选择,这甚至更丑陋?
  3. 有人可以帮忙吗?

    谢谢,Nic。

1 个答案:

答案 0 :(得分:1)

你可以试试这个......

set the webpage_content to ""
tell application "Safari" to set the webpage_content to the text of document 1
tell application "TextEdit"
    activate
    set the text of the front document to the webpage_content
end tell