Re: Saving Safari documents as html?
Re: Saving Safari documents as html?
- Subject: Re: Saving Safari documents as html?
- From: "Nigel Garvey" <email@hidden>
- Date: Thu, 5 Jan 2006 15:02:53 +0000
David Duncan wrote on Thu, 5 Jan 2006 15:23:13 +1100:
>Within a script I'm trying to save web pages in Safari using the save
>statement from Safari's standard suite. I want to save as html
>source ("TEXT" filetype), which is what you get when you choose the
>"Page Source" option in Save As in Safari's file menu (such saved
>file names have the ".html" suffix).
>
>However, with these lines...
>
> save window 1 as "TEXT" in outputFile --outputFile contains the
>path and file name
>OR save window 1 in outputFile
>
>... I get a ".download" suffix attached to the file name and the file
>type is literally blank, null. The files contain images and not just
>html source. It doesn't seem to make any difference what you specify
>as the file type.
I think you're supposed to save the document rather than the window,
though the effect seems to be the same, in Safari 2.0.2. Strange. (I
can't tell about images because my Tiger machine's not connected to the
Net.) If the file's renamed after it's saved, Safari recognises it as an
HTML file rather than a download file:
tell application "Safari"
activate
set fileName to (name of document 1) & ".html"
set savePath to (path to desktop as Unicode text) & fileName
save document 1 in file savePath
end tell
tell application "Finder"
if file (savePath & ".download") exists then
set name of file (savePath & ".download") to fileName
end if
end tell
This doesn't work with Safari 1.0.3, whose 'save' command doesn't
recognise its own 'in' parameter. However, the following seems to word
well with both versions:
tell application "Safari"
activate
set docSource to source of document 1
-- Can't get names of documents in Safari 1.0.3.
set docName to name of window 1
end tell
-- Get the source code as plain text.
set docSource to «class ktxt» of (docSource as text as record)
set savePath to (path to desktop as Unicode text) & docName & ".html"
set fRef to (open for access file savePath with write permission)
try
set eof fRef to 0
write docSource to fRef
end try
close access fRef
tell application "Finder"
tell file savePath
set {creator type, file type} to {missing value, missing value}
end tell
end tell
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden