首页 文章

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

提问于
浏览
2

我希望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 Programming Language - Official Website“无法保存为”python.htm“ . ”

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

“AppleScript错误
Safari出错:AppleEvent处理程序失败 . “

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

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

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

奇怪的是,我将“获取文档1”和“保存文档1”行移到“tell application safari”块之外,它将applescript保存为“python.htm”,用Firefox打开时看起来很傻 . 所以问题似乎是Safari无法保存而不是osx .

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

我更新了几次重启的软件 .

这是我的版本:

Safari:版本5.1(6534.50)
OSX Snow Leopard:版本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?

有人猜到了?谢谢 .

1 回答

  • 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这是不是一个苹果板?无论如何,也许原来的帖子应该可以工作,我只是不知道更好 . 我想如果人们在董事会或通过谷歌找到这个,答案可能会有所帮助或者mods只是想要删除它,如果这是一个明显的解决方案) .

相关问题