Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jimmy43

macrumors regular
Original poster
Apr 9, 2008
105
81
Hey everyone, apparently it's easy to do this but I have no idea what i'm doing.

I want to take snapshots of websites (they are only on my local machine) and make little images of them. There is a long list of them so I'd like to automate this.

Some help?:)
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
This should work:

Code:
property N : 0

on justDomain(URLvar)
	
	set TID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "."
	set dumVar to second text item of URLvar
	set AppleScript's text item delimiters to TID
	return dumVar
	
end justDomain


tell application "Safari"
	activate
	
	set URLList to {"http://www.yahoo.com/", "http://www.google.com/", "http://www.bing.com/"}
	
	repeat with u in URLList
		set the URL of document 1 to u
		
		set N to N + 1
		delay 5
		
		set picPath to ((POSIX path of (path to desktop)) & my justDomain(u) & " " & N & ".png") as string
		do shell script "screencapture -tjpg " & quoted form of picPath
			
	end repeat
		
end tell

Credit where credit's due department: You can thank TUAW for the bulk of the screen capture code.

You need to replace my URLList with the sites you want. Put the URLs in quotes, separated by commas and surrounded by curly brackets. This script will break otherwise.

There's one issue ... and that's the "delay 5." If there isn't some delay, the screencapture could grab the wrong web site. Ideally, there should be some tight repeat loop that compares the URL of the current window to the URL you want.

Delay 5 works on my machine. ymmv.

mt
 

jimmy43

macrumors regular
Original poster
Apr 9, 2008
105
81
You are my hero! it works great. I now need to figure out how to call this from a php script and pass it that list of URLs.. but this is already nice.

Thank you :D:D:D
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
Does it have to be PHP? In what form is your list of web sites? Chances are it can be done all in AppleScript ... which might save you some maintenance in the long run.

mt
 

jimmy43

macrumors regular
Original poster
Apr 9, 2008
105
81
Yes, so the php part dynamically scans the folder tree and creates links to these local websites. I wanted to have screenshots for these though so it's easier for people to preview the site. It's like a mini web-portal for people in my office.

Now I'm trying to see if I can get applescript to do the same thing, i.e. scan the folder tree and generate previews for those sites... Any idea how i can get the set URLList to {"... part to just be somethign like
set URLList to {"mylocalsite.1", "mylocalsite.2"} ..etc?:rolleyes:
 

jimmy43

macrumors regular
Original poster
Apr 9, 2008
105
81
Actually I got it all working! Thanks for your help again. Here is my script:


tell application "Safari"
activate

tell application "Finder"
set URLList to get name of folders of folder ("/Volumes/.../" as POSIX file)
end tell


repeat with u in URLList
set the URL of document 1 to "http://" & u

delay 5

set picPath to ("/Volumes/.../screenshots/" & u & ".jpg") as string
do shell script "screencapture -tjpg " & quoted form of picPath

end repeat

end tell

and run like so:

sudo osascript screencapturerer.scpt

Thanks again for all your help!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.