I'm trying to create an Automator script that removes portion of a filename after a delimeter while preserving the extension.
Files are usually called like 1-cropped_DSC5888.jpg, 2-cropped_Whatsapp75.png etc. I want to remove everything after _ and keep only the part with number and '-cropped' so like: 1-cropped.jpg
I tried it with this script
on run {input, parameters}
try
set AppleScript's text item delimiters to {"_"}
set theFileNameList to {}
repeat with thisItem in input
set the end of theFileNameList to text item 2 of (thisItem as text)
end repeat
set AppleScript's text item delimiters to {}
return theFileNameList
on error eStr number eNum
display dialog eStr & " number " & eNum buttons {"OK"} ¬
default button 1 with icon caution
set AppleScript's text item delimiters to {}
return
end try
end run
But this removes the part I want to keep and keeps the part I want to delete. Also it gives me just an output, but doesn't rename the actual files. Any help with this, please?