I tried to make this script as scalable as possible, but your situation is pretty unique. The script will find any numbers in the file name and remove them (so necessary numbers in the main file name are at risk). Anyways, here it is:
# NOTE* Move all the files you want to edit into a separate folder.
# NOTE* Make sure they have all the same file extensions as declared below.
set file_extension to ".jpg" # <- CHANGE IF NECESSARY
tell application "Finder"
# Gets the contents of the folder the user selected.
set file_list to entire contents of (choose folder)
# Runs this code for every item in the folder.
repeat with file_index from 1 to (count file_list)
# Gets the current file to be processed.
set selected_file to (item file_index of file_list)
# Calls the specified handler to remove the unnecessary numbers and ammend the new number.
set selected_file_name to my change_numbers((name of selected_file), file_index, file_extension)
# Applies the new name.
set name of selected_file to selected_file_name
end repeat
return "done"
end tell
# Handler to process the file name.
on change_numbers(file_name, file_index, file_extension)
# First pass; removes the unnecessary numbers.
set AppleScript's text item delimiters to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set file_name_items to (every text item of file_name)
set AppleScript's text item delimiters to ""
set file_name to (file_name_items as string)
# Second pass; removes the file_extension and replaces it with the version that has the new number attatched.
set AppleScript's text item delimiters to file_extension
set file_name_items to (every text item of file_name)
set AppleScript's text item delimiters to ((file_index as string) & file_extension)
set file_name to (file_name_items as string)
set AppleScript's text item delimiters to ""
# Exit handler.
return file_name
end change_numbers
I based a lot of this on a few assumptions about your situation, so if something isn't working like how you need, I can help. (P.S., to any people more advanced in AppleScript, maybe the user, I feel like this script can be simplified, especially in the handler section at the bottom. Can someone help with that?)