Re-apply selection

In the script below, I convert html files to markdown files. After all the operations the initially selected items are not selected anymore.

How can I re-apply the selection and select the items again?

-- Created: Tuesday, 9. June 2020 14:59
-- Ugur T.
-- Convert `formated notes` to `markdown` via Pandoc
-- Dependencies: Pandoc - See:

tell application id "DNtp"
	-- Ask if user wants to delete original files
	set theTitle to "Delete original files?"
	set theDialogText to "Want me to delete original files?"
	set checkIfDeleteOriginal to display dialog theDialogText ¬
		buttons {"Do not delete", "Delete"} ¬
		default button "Do not delete" with title theTitle
		set selectedItems to selection
		if selectedItems is {} then error "Please select some records."
		repeat with selectedItem in selectedItems
			-- path of item
			set inputFileWithPath to path of selectedItem as string
			-- name and extension
			-- set itemName to name of selectedItem	
			set itemName to name of selectedItem
			set itemType to type of selectedItem as string
			-- skip if not "formatted note"
			if itemType ≠ "formatted note" then exit repeat
			-- destination path
			-- > temp folder
			set destinationPath to (the POSIX path of (path to home folder)) & "temp/"
			-- set destinationPath to the POSIX path of (path to temporary items from user domain as string)
			-- output file: markdown file
			set outputFileWithPath to (destinationPath & itemName & ".md")
			-- convert via Pandoc
			-- shell command: 
			--    pandoc --atx-headers --from html --to markdown_strict -o OUTPUT_FILE  INPUT_FILE
			do shell script "/usr/local/bin/pandoc  --atx-headers --from html --to markdown_strict -o " & (quoted form of outputFileWithPath) & " " & (quoted form of inputFileWithPath)
			-- finally move the new html file into DEVONthink
			-- first: index it
			set theRecord to indicate outputFileWithPath to (current group) -- or: (display group selector)
			-- second: move it into DEVONthink
			consolidate record theRecord
			-- now set the correct creation date (copy from original record)
			set date of theRecord to (date of selectedItem)
			set creation date of theRecord to (creation date of selectedItem)
			-- delete original?
			if checkIfDeleteOriginal = {button returned:"Delete"} then
				delete record selectedItem
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

Just set the selection of viewer window 1 to the original value (selectedItems)

Like so?

set selection of window 1 to selectedItems

Worked! Thanks :slight_smile: