Wait for Safari's print dialog being opened (does not work in OS 10.6)

In Leopard I could wait for the Safari’s print dialog being opened using

if exists window “Print” then

In Snow Leopard this does not work any longer. Has anyone experience how to know whether Safari’s print dialog has been opened?

My code for OS 10.5:


tell application "Safari"

		set waitTime to 0
		set printed to false

		repeat until printed or (waitTime > 30)

			--open print dialog
			tell application "System Events" to keystroke "p" using command down
			delay 1
			set waitTime to waitTime + 1
			
			--wait until print dialog has appeared
			if exists window "Print" then
				--press Print button
				tell application "System Events" to keystroke return
				
				--Wait until printing is finished
				delay 3
				repeat until not (exists window "Print")
					delay 1
				end repeat
				set printed to true
			end if
		end repeat

		if not printed then
			--document has not been printed within 30 seconds
		end if
	end tell

I found it in any of my other scripts here:


keystroke "p" using command down
				
repeat until exists sheet 1 of window 1
   delay 0.1
end repeat

To retain a reference to the print sheet:

set PrintSheet to a reference to sheet 1 of window 1
				
# Expand the "PDF" menu button (must be expanded before the menu is referencable)
click menu button "PDF" of PrintSheet

Hi,

that’s probably not a question of the OS but a question of the version of Safari.
Safari 4 uses a sheet instead of a window


activate application "Safari"
tell application "System Events"
	tell process "Safari"
		set waitTime to 0
		set printed to false
		
		repeat until printed or (waitTime > 30)
			
			--open print dialog
			keystroke "p" using command down
			delay 1
			set waitTime to waitTime + 1
			
			--wait until print dialog has appeared
			if exists sheet 1 of window 1 then
				--press Print button
				keystroke return
				
				--Wait until printing is finished
				delay 3
				repeat until not (exists window sheet 1 of window 1)
					delay 1
				end repeat
				
				set printed to true
			end if
		end repeat
	end tell
end tell
if not printed then
	--document has not been printed within 30 seconds
end if