Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Save selected text from Safari to a text file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Save selected text from Safari to a text file
Authored by: orpy on Feb 24, '04 07:27:44PM
This is the latest version of this script. It was amended last week so that it will save the text of the whole page if nothing is selected. I've also added the javascript tip that was posted in reply to my oriiginal post.
--File: SaveSelectedOrText.scpt
--Author: Martin Orpen
--Date: 13.02.2004
--Updated: 24.02.2004
--
--Requires OS X and Safari.
--This script will save selected text or a whole page
--as text if nothing is selected. Text is appended
--to a dated file on your desktop.
--
-- = = = = = =

set myData to ""

tell application "Safari"
	activate
	set myURL to URL of document 1
	--line below suggested by Lankhmart on macosxhints
	set myData to do JavaScript "getSelection();" in document 1
	if myData is "" then
		set myData to text of document 1 as text
	end if
end tell

set myDate to current date
set fPath to path to desktop
set fName to (do shell script "date \"+%Y-%m-%d\"") & ".txt"
set myFile to open for access file ((fPath as string) & fName) with write permission
write "=== " & return & "Date: " & myDate & return & "Text from: " & myURL & return & return & myData & return & return to myFile starting at eof
close access myFile
beep
Thanks to all those who responded with advice.

[ Reply to This | # ]
Save selected text from Safari to a text file
Authored by: anh on May 24, '04 09:43:04PM

This hint gives most of what I need but assumes that the web page is already open. I am trying to create an automated script that opens a web page, copies the content, and manipulates it. Problem is that the web site is often slow, so I would like to wait patiently for the page to load and then proceed. Is there a way to make the script wait until the page is loaded? Using the "delay XX" kludge is a bit hit and miss, so I would prefer a more elegant solution. Can anyone help? Thanks.



[ Reply to This | # ]
Save selected text from Safari to a text file
Authored by: duncman on Jul 19, '05 10:22:08AM

I can see I'm a little late in this but this script is pretty cool. I use it along with Book2Pod to save web sites to my iPod for reading later.



[ Reply to This | # ]