need a little help: rename record to comment

I am trying to rename a selection of files to their respective comments. As I do not have any idea about scripts I tried to combine the scripts which where already done to a new one which would do what I wanted: I came up with this:

tell application “DEVONthink Pro”
activate
try
set this_selection to the selection
if this_selection is {} then error “Please select some contents.”

	repeat with this_item in this_selection
		set current_comment to the comment of this_item
		set new_item_comment to current_comment
		set the comment of this_item to new_item_comment
	end repeat
	
	repeat with this_item in this_selection
		set current_name to the name of this_item
		set new_item_name to new_item_comment
		set the name of this_item to new_item_name
	end repeat
	
on error error_message number error_number
	if the error_number is not -128 then
		try
			display alert "DEVONthink Pro" message error_message as warning
		on error number error_number
			if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
		end try
	end if
end try

end tell

However it does rename now all the files to the same comment of the first of the selected items. How do I amend the script so that it does one after the other?

from a very short look, your mistake is that you have two independent repeat-loops. The fist loop replaces the comment with itself and the second loop takes the last comment from the first loop as name for every file (But you wrote that it is the first comment … strange)

Anyway: if you only want to set the comment as name this should do (instead of the two loops you have):

repeat with this_item in this_selection
set the name of this_item to the comment of this_item
end repeat

hope that helps
Johannes

Well that worked very nicely, thank you.

As you wrote it, it looks all so plain and logical now. As today was the very first time, I did look at a script (without knowing really anything about how to read or write one) I tried to use existing scripts and combined them to achieve the result I needed :smiley:

That is why it must have looked rather strange to someone who knows what he is doing. I reckon I will try to find some novice’s tutorial to apple scripts to get some basic understanding.

Thanks again!

Thomas