[DtPO 2.6.1] Bug in Rename using RegEx script

The optional Rename using RegEx script strips double-quotes and probably other characters. For example, a document named:

This is “a test” document

… will be renamed:

That is a test document

… after replacing This with That.

I’d also like to re-suggest allowing the script to accept an empty replacement string; see:

here
here

This script should support double-quotes:


property pTitle : "DEVONthink Pro Batch Rename"

tell application "DEVONthink Pro"
	try
		set sourcePattern to display name editor pTitle info "Source pattern:"
		set destPattern to display name editor pTitle info "Destination pattern:"
		
		if sourcePattern is not "" and destPattern is not "" then
			set selectedItems to selection
			repeat with selectedItem in selectedItems
				set itemName to name of selectedItem
				set transformedName to do shell script "echo " & quoted form of itemName & " | sed -E 's/" & sourcePattern & "/" & destPattern & "/g'"
				set name of selectedItem to transformedName
			end repeat
			
		end if
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

It does - thanks!

Surely there’s a nicer way to do it, but deleting and destPattern is not “” allows it to accept ‘’ (two single quotes) as an empty destination pattern so it’s usable for removing unwanted text from item names.

I’m satisfied using this instead of the less capable Rename using RegEx script.