Open several sites in Safari and take a screenshot of them.

I wanted to post this script because I was only able to figure it out after browsing the forum here. Thanks for all the help and maybe this will help someone else out.

I was asked to figure out a way to open a list of websites and take a screenshot of them so that the ‘decision makers’ could see what a site looked like outside of an email and in a real world situation. I’d never used AppleScript before and figured this would be a good learning experience. This script opens a site, pauses 3 seconds, takes a screenshot then moves on to the next site.


set the URL_list to {"http://intranet", "http://xkcd.com", "http://arstechnica.com"}

property N : 0

repeat with i in URL_list
	tell application "Safari"
		make new document at end of documents
		set URL of document 1 to i
	end tell
	
	delay 3
	
	set N to N + 1
	set picPath to ((POSIX path of (path to desktop)) & "Picture_" & N & ".png") as string
	do shell script "screencapture -tpng " & quoted form of picPath
	
end repeat