I am trying to automate batch renaming of images sequentially by using a simple Applescript. But I am having difficulty telling the script that there are images in the same folder that already have the same name.
For example, I have three images of a cat that are named Hello World 1Hello World 1, Hello World 2Hello World 2 and Hello World 3Hello World 3.
In the same folder I also have three more of the same image but with the name Test Image 1, Test Image 2 and Test Image 3.
I want to rename all of the "Test Images" to Hello World 4Hello World 4, Hello World 5Hello World 5 and Hello World 6Hello World 6 but I get the following error:
error "Finder got an error: The operation can’t be completed because there is already an item with that name." number -48
How do I tell the script that there are other images in this folder that have the same name and that it needs to start from "Hello World 4" and continue renaming the rest of the images?
Please note that I will be using this as an embedded script in an application called Hazel (noodlesoft.com) and it does not accept handlers. So I will need a solution that does not use a handler.
Here is the script I am using that gives me the error when I try to rename the "Test Images":
tell application "Finder"
set all_files to every item of (choose file with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list
set new_name to "Hello World"
repeat with index from 1 to the count of all_files
set this_file to item index of all_files
set {itemName, itemExtension} to {name, name extension} of this_file
set index_prefix to " "
if itemExtension is "" then
set file_extension to ""
else
set file_extension to "." & itemExtension
end if
set the name of this_file to new_name & index_prefix & index & file_extension as string
end repeat
end tell