help printing all open tabs in Safari

I cobbled together this script to print all the open tabs in a Safari window:


set N to {}
tell application "Safari"
	repeat while name of window 1 is not in N
		set end of N to name of window 1
		activate application "Safari"
		print window 1
		delay 1
		tell application "System Events" to tell process "Safari" to keystroke "}" using {command down}
	end repeat
end tell

I saved that as an application and sometimes it even works. Most times, it will print some of the tabs then the application will stop with a ‘can’t continue’ message that doesn’t tell me anything useful.

Can anyone suggest someway to make this work reliably?

Thanks!