Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript: Safari - Save As Web Archive

The title says it all: Can someone tell me please how - most likely via UI scripting, since I can't see anything in the dictionary - I can get Safari to save the front most document as a Web Archive using AppleScript?

Posted on Sep 24, 2011 3:47 AM

Reply
Question marked as Best reply

Posted on Sep 24, 2011 5:25 AM

Hi Bernard,


The following script should do the trick:


tell application "Safari" to activate


tell application "System Events"

tell process "Safari"

keystroke "s" usingcommand down-- Save As…

repeat until sheet 1 of window 1 exists

delay 0.1

end repeat

keystroke "d" usingcommand down-- save to Desktop

tell sheet 1 of window 1

clickpop up button 1 of group 1

keystroke "W" & return-- Web Archive

keystrokereturn-- Save

if sheet 1 exists then -- that is "sheet 1 of sheet 1"

click button "Replace" of sheet 1

end if

end tell

end tell

end tell

18 replies

Jan 17, 2014 3:22 PM in response to Neville Hillyer

Essentially, if I understand well, you have replaced


repeat while enabled of menu item "Save as…" of menu 1 of menu bar item "File" of menu bar 1 is false

endrepeat


with


repeat while enabled of menu item "Stop" of menu 1 of menu bar item "View" of menu bar 1 is true

end repeat

in the “tellapplication "System Events" totellprocess "Safari"” block.

That's a very interesting alternative, indeed. Thanks for that information.


By the way, you could remove “istrue” from the last statement above in order to be still more concise. 😉

AppleScript: Safari - Save As Web Archive

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.