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.