Importing a list of URLs as bookmarks

This script creates a bookmark for each line of the selected records.

If you’re dealing with a large number of URLs it might be that you have to set a delay inside the repeat loop in order to get bookmarks with proper names (not sure this is necessary, but I think after a script already added hundreds of bookmarks the last ones didn’t get a proper name anymore).

-- Create bookmarks from text

tell application id "DNtp"
	try
		if not (exists viewer window 1) then error "Please select a record"
		set theRecords to selection of viewer window 1
		if theRecords = {} then error "Nothing selected"
		
		set theGroup to display group selector "Create bookmarks in:"
		
		repeat with thisRecord in theRecords
			set theText to plain text of thisRecord
			set theURLs to paragraphs of theText
			repeat with thisURL in theURLs
				set thisURL to thisURL as string
				if thisURL ≠ "" then
					create record with {type:bookmark, URL:thisURL} in theGroup
					#delay 1
				end if
			end repeat
		end repeat
		
		open window for record theGroup
		activate
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell