Remove last 5 digits of filename and add sequence number
I need to rename files as follows:
Existing file name structure is:
UWSTD-NV-16999.jpg
UWSTD-NV-17001.jpg
UWSTD-NV-17006.jpg
I would like to rename like the following:
UWSTD-NV-1.jpg
UWSTD-NV-2.jpg
UWSTD-NV-3.jpg
I have a script that will remove the numbers only from the end, but I'm not sure how I can modify it to add a sequence number on the end.
on run {input, parameters}
repeat with thisFile in input
tell application "Finder"
set {theName, theExtension} to {name, name extension} of thisFile
if theExtension is in {missing value, ""} then
set theExtension to ""
else
set theExtension to "." & theExtension
end if
set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part
set theName to (do shell script "echo " & quoted form of theName & " | sed 's/[0-9]*$//'") -- strip trailing numbers
set name of thisFile to theName & theExtension
end tell
end repeat
return input
end run
macOS Sierra (10.12.4)