safari screen capture

I am trying to capture a picture of the webpage that a previous script has opened.
I have tried with paparazzi which works fine but if the url is sent a second time, the webpage changes.
I have gone to trying this script.

tell application "System Events" to tell process "Safari"
   set frontmost to true
   keystroke "4" using {command down, shift down}
   delay 1
   keystroke space
   delay 0.5
end tell

tell application "Extra Suites"
   ES move mouse {400, 24}
   ES click mouse
end tell

this seems like it should work but the keystrokes don’t seem to work. I can see the events going off in the event log but it just seems to put the curser at the end of the current page of safari with no action.

fyi the old script

tell application "Paparazzi!"
	activate
	set minsize to {1074, 700}
	set filename to confirmationo & ".jpg"
	set iconame to (true)
	capture theURL min size minsize
	repeat while busy
		-- To wait until the page is loaded.
	end repeat
	save as JPEG in (path to documents folder as Unicode text) & filepathend & filename icon iconame
	quit application "Paparazzi!"
end tell

You could always save as pdf instead of doing a screen capture.

set myDelay to 1

tell application "Safari" to activate
tell application "System Events" to tell process "Safari"
	keystroke "p" using command down
	delay myDelay
	click menu button "PDF" of sheet 1 of window 1
	delay myDelay
	click menu item "Save as PDF." of menu 1 of menu button "PDF" of sheet 1 of window 1
	delay myDelay
	click button "Save" of window "Save"
end tell

And if you need to convert the pdf to another format like a jpeg file then use image events…

set savePath to (path to desktop folder as text)
set aFile to choose file

tell application "Image Events"
	set myImage to open aFile
	save myImage as JPEG in savePath with compression level high
	close myImage
end tell

Both scripts will work fine but I need to save the file to a path instead of the desktop. I"m not sure how to do this.
I also altered the script to change the title of the saved file, store it in a specific folder.

set myDelay to 1

tell application "Safari" to activate
tell application "System Events" to tell process "Safari"
	keystroke "p" using command down
	delay myDelay
	click menu button "PDF" of sheet 1 of window 1
	delay myDelay
	click menu item "Save as PDF." of menu 1 of menu button "PDF" of sheet 1 of window 1
	delay myDelay
	keystroke confirmationo & ct
	click button "Save" of window "Save"
end tell

There’s no direct commands to do this because we’re gui scripting here, but I can think of 2 ways you might accomplish this. 1) gui scripting the “save as pdf” dialog box to make it save where you want or 2) save it to the desktop and then use Finder commands to move the file where you want.

If you choose #2 then you might have a problem because I don’t think the dialog box will always default to saving the file to the desktop. It usually defaults to the last place you saved a file this way… i.e. so it will probably change over time. Considering that, you may want to just save the file to wherever it goes and then do a search for the file name to locate its current location, and then move the located file to your chosen path. I’m thinking you could probably use spotlight commands to search for the file name so that you can locate it. A quick search on this board should turn up some examples of using spotlight to search and Finder commands to move the file.