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

How to tell Safari to open and save a web page

While on vacation, I would like to save a daily puzzle that occurs on a web site that uses the same URL for each new puzzle. Using the Energy Saver Preference panel, I can schedule a daily start up and shut down and add Safari to the Login Items. How would I tell Safari to open that URL and then save the web page to the Desktop?

PowerBook G4, Mac OS X (10.4)

Posted on Apr 29, 2008 9:22 AM

Reply
13 replies

Apr 29, 2008 11:43 AM in response to xnav

Thanks for the link, but for someone like me who doesn't know Applescript very well, the thread is full of suggestions that didn't quite work for the original poster who ended up stating:

"Script still hangs in saving window to DT, solved it by making a picture of the window and using that, does the job. thanks for thinking with me."

Anyone else with a suggestion of how to simply save the page to the desktop. I'm not concerned about the file name, as long as it is unique.

Apr 29, 2008 1:16 PM in response to Ralphjh

Using the thread, I came up with this, which works on my system:

tell application "Safari"
activate
make new document at end of documents
set URL of document 1 to "http://CROSSWORD_URL"
get document 1
delay 3
set pathToSave to (path to desktop as text) & ("Crossword ") & (do shell script "date '+%d-%m-%Y'")
save document 1 in file pathToSave
end tell

Replace CROSSWORD_URL with the correct link.

Apr 29, 2008 2:13 PM in response to xnav

Thanks for the reply. Your script does work, that is, it opens the URL and saves the page to the desktop. However, there is a problem with the saved document. If I save the page manually from the Safari File menu, I get the desired result. However, the document that is saved by the script contains a weird, truncated image of the graphic that I am interested in. Is there a way to tell Safari to save the document?

This is the URL that I wish to use. You can see for yourself what the problem is.

http://www.sudoku.org.uk/DailyKiller.asp?colour=please

Apr 29, 2008 3:47 PM in response to xnav

I now remember that I used to get the strange looking page when I saved it as "Page Source." If you go to the Safari File menu and select Save As... there is a Format selection menu at the bottom of the window. The correct Format should be "Web Archive." How would I modify the script to tell Safari to save as a Web Archive?

Apr 29, 2008 8:08 PM in response to Ralphjh

Ralphjh,

An Automator workflow can save the page in a web archive format:

First download the Save Safari Web Archive workflow.

I would add two additional actions at the beginning of the workflow, each from Automator's Safari library, so that your final workflow would look like this:

1) *Get Specified URLs* -- Deselect or use the minus sign to remove the default www.apple.com address. Open your puzzle page in Safari, make it frontmost, and click on the Current Safari Page button.

2) *Display Webpages*

3) *Run AppleScript* -- No need to modify the existing script.

4) *Get Selected Finder Items*

5) *Move Finder Items* -- The desktop is default.

Save the Workflow as File Format: application, and add it to your Login Items.

It all may be for naught however. I suspect that upon your return from vacation, you'll be disappointed to find that opening any one of the saved files will only result in opening the current day's puzzle. For example, on Tuesday April 29th, the puzzle linked from the URL you posted opened the puzzle for +that day,+ Puzzle Number 760. A quick look at the 30 Day Killer archive (scroll down the page) reveals that each day's puzzle has its own URL. The actual URL for Puzzle Number 760 is:

http://www.sudoku.org.uk/DailyKiller.asp?day=29/04/2008

You'll notice that the URLs for the individual days' puzzles in the Killer Archive differ only in the dates appended to them. You would likely need to find a way to incorporate that pattern into an AppleScript -- correlating the current date to the updated URL.

Regards, Andrew99

Apr 29, 2008 9:07 PM in response to xnav

Andrew & xnav:

I did use an Automator Workflow. I found it on the following site:

http://automatorworld.com/archives/save-safari-web-archive/

I combined it with a few lines of xnav's script. No problem with the puzzle of the day. It will be saved each day with a unique file name. The URL is always the same for the puzzle of the day. Here is the final script (it actually opens a Save dialog) and it works:

--on run {input, parameters}
tell application "Safari"
activate
make new document at end of documents
set URL of document 1 to "http://www.sudoku.org.uk/DailyKiller.asp?colour=please"
get document 1
delay 3
set theWin to (name of window 1 as string)
-- need to replace any : with - in theWin
tell me to set theFile to (switchText of theWin from ":" to "-")
if theWin is not "Untitled" then
set theFile to (path to desktop as string) & theFile & ".webarchive"
end if
end tell

if theWin is not "Untitled" then
tell application "System Events"
tell process "Safari"
click (menu item "Save As…" of menu 1 of menu bar item "File" of menu bar 1)
keystroke "D" using command down
click (pop up button 1 of group 1 of sheet 1 of window theWin)
delay 1
click (menu item 2 of menu 1 of pop up button 1 of group 1 of sheet 1 of window theWin)
delay 1
click (button "Save" of sheet 1 of window theWin)
end tell
end tell
end if

tell application "Finder"
select (theFile as alias)
end tell

--end run

to switchText of t from s to r
set d to text item delimiters
set text item delimiters to s
set t to t's text items
set text item delimiters to r
tell t to set t to beginning & ({""} & rest)
set text item delimiters to d
t
end switchText

Apr 29, 2008 10:26 PM in response to xnav

xnav,

You are correct; my fears were unfounded. Now that it's past midnight here on the east coast U.S., the current puzzle linked directly from sudoku site is Puzzle Number 761, whereas the web archive I saved from yesterday, the 29th, does indeed retain Puzzle Number 760.

And to Ralphjh, Good deal! I'm glad a solution was found...

Andrew99

How to tell Safari to open and save a web page

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