simple script to change names doesn't

I’ve converted a bunch of PDF files (made from web pages) to web archives. The original record names ended with “.pdf”, which I’d like removed. I put together the following little script to do that:


set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
tell application "DEVONthink Pro"
	set theRecords to selection
	repeat with theRecord in theRecords
		set theName to name of theRecord
		set theNewName to (text items 1 thru -2 of theName)
		set name of theRecord to theNewName
	end repeat
end tell
set AppleScript's text item delimiters to oldDelims

This runs without any errors. It also runs without actually changing the name of the selected records. I tried collapsing and expanding the folder, since sometimes DEVONthink needs to “refresh” the list. I’ve even tried closed and restarting DEVONthink itself. Nothing. The name, on both the list and the info pane, does not change.

Maybe it’s because I’ve spent all day writing a much more complicated script, but I can’t figure out why this isn’t working.

You need to explicitly coerce theNewName (which AppleScript implicitly made into a list) to a string.

Change


set theNewName to (text items 1 thru -2 of theName)

to


set theNewName to (text items 1 thru -2 of theName) as string

and the script will work. (Tested it over here.)

Yes, that was exactly the problem. Thanks much!