On Jan 15, 2014, at 10:00 AM, koenig.yvan <
email@hidden> wrote:
set p2d to path to desktop as text
tell application "Safari"
name of document 1
save document 1 in (p2d & result & ".webarchive")
end tell
does the job
Thanks for your help.
From within the Safari window I get the message The document "Untitled" could not be exported as "Untitled.webarchive". From within the AppleScript editor window I get the message "Safari got an error: AppleEvent handler failed."
When I search google I find similar postings for the error shown in the AppleScript editor window "Safari got an error: AppleEvent handler failed." number -10000.
I went ahead and rebooted and also tried on another computer but no change, I still get the error. I looked in the System Console but I don't see any messages relating to this. I'm not quite sure where I would look for log files or anything of that nature to sort of nudge me in the right direction.
Here is the script I used. Am I doing something wrong by making the document with properties statement?
set p2d to path to desktop as text
tell application "Safari"
name of document 1
save document 1 in (p2d & result & ".webarchive")
end tell
Also, I remember my trouble with using the AS-Obj-C library. I even still have the library from last year still saved in my Script Libraries folder, and I tried again just for fun. What happens is that when I successfully save a page, it shows me the login screen even though I already logged in via the visible Safari window on my desktop. I had recently learned how to tell Safari to make a document with properties { URL:"" } so I thought I'd try to save that as a webarchive.
Alex, sorry I never answered your question. Print to PDF would be good to try as well. I googled it and it appears to be GUI scripting, which I have not had much luck with. When I change Ivan's script from ".webarchive" to ".pdf" I get the same error, so I suppose it is GUI scripting related to get it to do that. I might try the GUI scripting, and that's where I ended up last year, but I ran into issues getting reproducible results all the time.
Thanks all for the responses.
V/r,
Bryan