Copy from Safari to Textedit, then repeat, over and over again.

Hi all,

I need to copy and paste all the text from over 200 webpages into a single Textedit document. I can then use the find and replace commands in Textedit to get the information into tabbed order (to create an address book for myself).

I’ve seen plenty of scripts to copy and paste from one to the other but am struggling to fit everything together for my needs.

Assuming I have all 200 windows open in Safari, I want to do the following to each page:

Select all
Close window

Go back to Safari

This repeats until all the windows are closed and the text is in one Textedit document.

Can anyone help?

Many thanks in advance if you can,



if you want the whole HTML source, use curl instead of Safari. For example the result of

do shell script "curl ''"

is the source of the Macscripter home page

If you want only the text, use the text property of Safari

tell application "Safari"
	text of document 1
end tell

Thanks, Stephen,

But how do I then get that to Textedit and keep repeating the process?

if all windows are open already, something like this

tell application "Safari" to set counter to count windows
repeat counter times
	tell application "Safari"
		set a to text of document 1
		close window 1
	end tell
	tell application "TextEdit"
		tell document 1
			set b to its text
			set its text to b & return & return & a
		end tell
	end tell
end repeat

Excellent, Stefan.

Just what I was after.

Saved me a few hours that has.

Big thanks!