Print to pdf

I am trying to save a pdf of a Safari web page. The page does not allow a Save as. PDF so, i want to be able to Print to PDF. I found this link, http://macscripter.net/viewtopic.php?id=36776. I am trying to get that to work. Here is a slightly modified versions without buildings strings with dialogs, and some log statements.


set SaveFolder to "/Users/stephenm/Documents/CDC/Shows/"
set eventFileName to "a.pdf"
tell application "Safari" to activate
tell application "System Events"
	tell process "Safari"
		keystroke "p" using command down
		tell front window
			repeat until exists sheet 1
				delay 0.02
			end repeat
			tell sheet 1
				click menu button "PDF"
				repeat until exists menu 1 of menu button "PDF"
					delay 0.02
				end repeat
				click menu item "Save as PDF." of menu 1 of menu button "PDF"
			end tell
		end tell

		log "about to save window"
		repeat until exists window "Save"
			delay 0.2
		end repeat
		log "save window"

		
		tell window "Save"
			keystroke "g" using {command down, shift down}
			repeat until exists sheet 1
				delay 0.2
			end repeat
			tell sheet 1
				--Subject_Added Peter to test how to pass file name
				set value of text field 1 to SaveFolder
				click button "Go"
			end tell
			repeat while exists sheet 1
				delay 0.2
			end repeat
			set value of text field 1 to (eventFileName) as string
			click button "Save"
		end tell
	end tell
end tell

The “about to save window” log triggers but the “save window” log never triggers. Additionally, showing events shows a bunch of

exists Window “Save” of process “Safari”
→ false

Using UIBrowser it appears the Save Window is now a sheet. I tried to change the script to be something like,


		log "about to save window"
		repeat until exists sheet "Save"
			delay 0.2
		end repeat
		log "save window"

and


		log "about to save window"
		repeat until exists sheet 1
			delay 0.2
		end repeat
		log "save window"

Neither get me closer to a solution. Anyone with another suggestions?

Browser: Safari 534.50
Operating System: Mac OS X (10.8)

Hi,

in Safari 6 the Save window is a sheet, so you have to reference


 repeat until exists sheet 1 of sheet 1 of front window
           delay 0.2
       end repeat
       log "save window"

Thanks,

That did the trick!