Paste With Quotes Escaped

Whipped this one up to paste string constants containing quotes into the Script Editor. Can’t seem to get it to work generally, though.

set TID to AppleScript's text item delimiters

set myclip to the clipboard as text

if "\"" is in myclip then
	set AppleScript's text item delimiters to "\""
	set t to every text item of myclip
	set AppleScript's text item delimiters to "\\\""
	set myclip to t as text
end if

try
	tell application "Script Editor"
		tell front document
			set contents of selection to myclip
		end tell
	end tell
end try

set AppleScript's text item delimiters to TID

Model: PowerBook G4
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

That works fine for me.