rename files in sequence script

Hello to all DT users —

I was wondering if someone is using a script to rename files in sequence. For instance:

file AZD → my choosing name 1
file DAX → my choosing name 2
file BHF → my choosing name 3
file XCF → my choosing name 4
file HLM → my choosing name 5

My main problem is renaming image files that have different original names (some of them very weird), but are of the same subject.

Any help would be very welcome, since my applescript knowledge is quite limited. :blush:

– MJ

If there’s no other solution maybe you could export the images, rename the files using one of the multitude of OS X renaming utility (e.g. Name Mangler, then import them back into DT. Or possibly rename them before adding to DT.

Tried that and it didn’t work:

  1. if I export the files, then rename them and import back to DTP, for some reason the files maintain the old name

  2. if I download the files to the mac, rename them and then import them to DTP, they lose the source url information

I feel kind if doomed here. The last resource is change the name one by one. Not fun when you have 20-30 files. :frowning:

Modifying the script from http://www.devon-technologies.com/scripts/userforum/viewtopic.php?f=20&t=11832#p55430

tell application id "com.devon-technologies.thinkpro2"
   try
      set counter to 0
      set theSelection to the selection
      if theSelection is {} then error "Please select some contents."
      repeat with theRecord in theSelection
         set counter to counter + 1
         try
            set name of theRecord to "my choosing name " & (counter as string)
         end try
      end repeat
   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

but 20-30 files really isn’t that bad :slight_smile:

I’m curious as to why sjk’s suggestion doesn’t work in your case. Renaming the files in Finder using a rename tool should permanently change the name and DTP importing those renamed files shouldn’t revert the name. Where are the files to begin with? It seems from your second comment that they are perhaps on a server somewhere or in the cloud.

I found it weird as well. However, the files were only on my HD. No server or cloud.

I could not figure out why the files, once reimported to DTP, reverted to the original name. It was almost like something was left behind in DTP (it shouldn’t since I deleted the files in DTP after exporting them to the desktop) that recognized the files as being there before.

Thank you for this :slight_smile:. It works almost perfectly.

… So can I ask another favor? (I tried to change the script myself, but to no good end.) If there could be a windows pop-up asking to rename the files in selection. Then the new name would be the input name on that window plus the number sequence.

Something like:


Click for full size

Well… it is when you end up doing that many times a week. :confused: (Not as bad as thousands files, I agree.)

Puzzling to me, too. Even if a DEVONtech_storage file (why no .plist extension, btw?) was referenced during importing that shouldn’t have any influence on the renamed files.

I did a little digging and was able to modify the script so that it asks for a prefix, then applies it to all the files followed by a sequential number.


display dialog "Enter File name prefix:" default answer "" buttons {"Cancel", "Continue"} default button 2
set the this_text to text returned of the result
tell application id "com.devon-technologies.thinkpro2"
	try
		set counter to 0
		set theSelection to the «class DTsl»
		if theSelection is {} then error "Please select some contents."
		repeat with theRecord in theSelection
			set counter to counter + 1
			try
				set name of theRecord to this_text & " " & (counter as string)
			end try
		end repeat
	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 is coded to only put a space between the filename and the number, so if you want another separator like a dash, you’ll either have to modify the script or use the search and replace script. Also, if you have Windows-style suffixes on the files like .JPG, they will be wiped out.

I remember the same thing happening to me when I tried to rename a series a files using ABetterFinerRenamer. For some reason, DTP resorted back to the original filenames, no matter how I imported them back into the program.