【问题标题】:Applescript: Safari Can't Save Web Page (AppleEvent Handler Fails Error)Applescript:Safari 无法保存网页(AppleEvent 处理程序失败错误)
【发布时间】:2011-10-19 10:42:33
【问题描述】:

我希望 Safari 使用 Apple automator 下载并保存网页。打开 Safari 窗口后,我在 AppleScript 编辑器中运行以下脚本:

tell application "Safari"
    set URL of document 1 to "http://www.python.org"
    delay 6
    get document 1
    delay 6
    save document 1 in "/mydir/" & "python" & ".htm"
end tell

Safari 显示正确的 url,但随后我在 safari 中收到以下错误:

“文档“Python编程语言-官网”无法保存为“python.htm”。”

我在那个错误框上单击“确定”,然后 AppleScript 编辑器在一个对话框中给我这个错误:

“AppleScript 错误
Safari 出现错误:AppleEvent 处理程序失败。”

AppleScript Editor 在底部有一个名为“Result”的框,它还显示以下消息:

"error "Safari 出现错误:AppleEvent 处理程序失败。" number -10000"

而且网页不会保存。我不知道是什么导致了这个 b/c 我 99% 确定我过去使用过相同(或相似)的代码来保存页面。

奇怪的是,我将“get document 1”和“save document 1”行移到了“tell application safari”块之外,并将applescript保存为“python.htm”,当用Firefox打开时,它看起来很傻。所以问题似乎是Safari不能保存而不是osx。

另外,我使用 chmod 将目标保存目录的所有权限更改为 all(在 bash 中使用 777 参数)。

我更新软件重启了好几次。

这是我的版本:

Safari:版本 5.1 (6534.50)
OSX 雪豹:版本 10.6.8 AppleScript 2.1.2
AppleScript 编辑器:版本 2.3 (118)
我被束缚在手机上,将其用作移动接入点。我不知道这是否重要。

我认为这个人也有同样的错误,但没有答案:

Why does this AppleScript get an "AppleEvent handler failed" error on Mac OS X 10.5 Leopard?

有人猜到了吗?谢谢。

【问题讨论】:

  • 可能是save 命令的错误。即使tell application "Safari" to save front document 也不起作用,它会报告-10000 错误。

标签: safari applescript web-crawler appleevents


【解决方案1】:

我不知道真正的答案,但它有 50 多个浏览量和风滚草,所以我想我会发布一些东西。

显然你应该使用 curl:

tell application "Safari"
    set URL of document 1 to "http://www.python.org"
    delay 6
    get document 1
    set my_html to URL of document 1
end tell

set my_new_file to "/Users/your_user_name/python.htm"
set my_script to "curl " & my_html & " >> " & my_new_file

do shell script my_script

(我在 macscripter 上看到了一篇帖子,他们说这是“唯一可行的方法”,所以可能无法在 Safari 中使用“另存为”,这是一个常见的 applescript 错误,但没有得到回答 b/ c 这不是一个 AppleScript 板?无论如何,也许原来的帖子应该可以工作,我只是不知道更好。我想如果人们在板上或通过谷歌找到这个,答案可能会有所帮助,或者也许如果这是一个明显的解决方案,mods 只是想删除它)。

【讨论】:

  • 不,这不是一个显而易见的解决方案。记得使用quoted form of my_new_file。如果你这样做,你的解决方案就会奏效。 :)
  • 我从我的 applescript 编辑器中粘贴了它,它工作正常,所以我认为它工作正常。在倒数第二行,my_new_file 是在倒数第三行设置的字符串变量。所以也许我的行太多而且不可读。您可以删除 "end tell" 之后的所有内容并将其替换为以下行:do shell script "curl " & my_html & " >> " & "/Users/you_user_name/python.htm"
猜你喜欢
  • 2012-02-09
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
  • 2011-07-15
相关资源
最近更新 更多