How to automatically open the URL of a selected record in Sa

I have a lot of RTF records with attached URLs. When I select such a record, this script will open the URL in Safari in the background. So if I need to look at the original page, I just switch to Safari.

-- This script is ment to be attached to records in DevonThink. 
-- When the record is selected, its URL (if any) will be opened in the background, with Safari. The same tab will be reused for consecutive pages. 
-- Inspired by Tom Shannon (
-- Created by Tommy Sundström

on triggered(theRecord)
		tell application "DEVONthink Pro"
			set theURL to URL of theRecord
			if theURL is not {} then
				tell window 1 of application "Safari"
					set focused_tab_URL to (URL of current tab) as text
					-- Make marked url
					set rubycode to "puts '" & theURL & "'.match(/\\?/)" -- checks if url contains "?"
					set url_has_questionmark to do shell script ("ruby -e " & quoted form of rubycode)
					if url_has_questionmark is "nil" then
						-- No questionmark, so it needs to be included in the marker
						set markedURL to theURL & "?devonthinkpreview"
						-- URL already has a questionmark
						set markedURL to theURL & "&devonthinkpreview"
					end if
					-- Is focused_tab created by this script (ie does it contain "&devonthinkpreview" in the URL)?
					set rubycode to ("puts '" & focused_tab_URL & "'.match(/devonthinkpreview/)") -- checks if url contains "devonthinkpreview"
					set tab_created_by_me to do shell script ("ruby -e " & quoted form of rubycode)
					if (tab_created_by_me is "nil") then
						-- Not created by this script, so need to make a new
						set current tab to make new tab with properties {URL:markedURL}
						-- Created by this script, so can be reused
						set URL of current tab to markedURL
					end if
					-- activate -- Uncomment to give Safari focus.			
				end tell
			end if
		end tell
	on error error_message number error_number
		-- Ignore
		display dialog error_message -- For debugging
	end try
end triggered