Renaming Multiple Files Numerically

I have about 500 jpg’s that are named with very similar file names:

For Example:

Word1_Word2_Random Picture Name 1.jpg
Word1_Word2_Random Picture Name 2.jpg
Word1_Word2_Random Picture Name 3.jpg
Word1_Word2_Random Picture Name 4.jpg

The First part of the file names (Word1_Word2_) is fine. I need to grab the part of each file name that has a random name and re-name them numerically so they look like the following:


I have found some scripts that work as a search and replace method, and other’s that can change file extensions, but none that will change part of a file name in the middle. Any ideas?

I think this is what you are looking for:

set secondPart to 0

repeat with aFile in theFiles
	set firstPart to "FirstPart" --you can modify this yourself
	set secondPart to secondPart + 1
	set the displayed name of aFile to firstPart & secondPart
end repeat

If you’re wondering, a file’s name includes its extension, while displayed name does not. That’s why I used displayed name.