Applescript:Safari 无法保存网页(AppleEvent 处理程序失败错误)

发布于 11-27 16:05 字数 1335 浏览 1 评论 0原文

我希望 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.h”。嗯”。

我在该错误框中单击“确定”,然后 AppleScript 编辑器在对话框中给出此错误:

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

AppleScript 编辑器底部有一个名为“结果”的框,并且还显示以下消息:

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

并且网页将无法保存。我不知道是什么原因导致这个 b/c 我 99% 确定我过去使用过相同(或类似)的代码来保存页面。

奇怪的是,我将“获取文档 1”和“保存文档 1”行移到“告诉应用程序 safari”块之外,并将 applescript 保存为“python.htm”,当用 Firefox 打开时,它看起来很愚蠢。所以问题似乎是 Safari 无法保存,一般也不能保存,

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

我更新了软件,然后重新启动了几次

。 :

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

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

为什么这个 AppleScript 在 Mac OS X 10.5 Leopard 上会出现“AppleEvent handler failed”错误?

有人猜到吗?谢谢。

I want safari to download and save a web page using apple automator. With a Safari window open, I run the following script in AppleScript Editor:

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 displays the correct url, but then I get the following error in safari:

"The document “Python Programming Language – Official Website” could not be saved as “python.htm”."

I click "ok" on that error box and then AppleScript Editor gives me this error in a dialog box:

"AppleScript Error
Safari got an error: AppleEvent handler failed."

AppleScript Editor has a box at the bottom called "Result" and it also displays the following message:

"error "Safari got an error: AppleEvent handler failed." number -10000"

And the web page won't save. I don't know what's causing this b/c I'm 99% sure that I was using this same (or similar) code to save pages in the past.

Strangely, I moved the "get document 1" and "save document 1" lines outside of the "tell application safari" block and it saved the applescript as "python.htm" and it looked all goofy when opened with Firefox. So the problem seems to be that Safari cannot save and not osx generally.

also, I used chmod to change all permissions on the target save directory to all (used 777 argument in bash).

I updated the software restarted several times.

Here's my versions:

Safari: Version 5.1 (6534.50)
OSX Snow Leopard: Version 10.6.8
AppleScript 2.1.2
AppleScript Editor: Version 2.3 (118)
I'm tethered to my cell phone, using it as a mobile access point. I don't know if that matters.

I think this guy got the same error but no answers:

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

Anybody got a guess? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞2024-12-04 16:05:34

我不知道真正的答案,但它有 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 板?无论如何,也许原来的帖子应该有效,我只是不知道人们是否在板上或通过谷歌找到了这个答案。可能有帮助或者也许是模组只是想删除它(如果这是一个明显的解决方案)。

I don't know the real answer, but it has 50+ views and a tumbleweed, so I figured I'd post something.

apparently you're supposed to use 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

(I saw a post on macscripter and they said this was "the only way to go" so maybe there is no way to use "save as" in Safari and this is a common applescript error but it was not answered b/c this is not an applescript board? Anyway, maybe the original post is supposed to work and I just don't know any better. I figured if people were finding this on the board or through google, an answer may be helpful or maybe the mods just want to delete it if this is an obvious solution).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文