BTW, here is the code that I use to rename the files now.
tell application "Finder"
set that_folder to (path to desktop folder)
set a_list to every file in folder "ImageRename" of folder that_folder
repeat with i from 1 to number of items in a_list
set a_file to (item i of a_list)
try
set fileName to name of a_file --> belts_0000s_0005_W102BT00.tif.jpg
set nameWithoutExtension to characters 13 through 20 of fileName --> W102BT00
set newName to (nameWithoutExtension & ".jpg") as text --> W102BT00.jpg
set name of a_file to newName --> rename the file
end try
end repeat
end tell
this is a more flexible version, the position of the delimiter character doesn’t matter
property delimiter : "W"
property newExtension : "jpg"
tell application "Finder" to set a_list to every file in folder "ImageRename" -- the desktop folder is the "root" folder of the Finder
set {TID, text item delimiters} to {text item delimiters, delimiter}
repeat with i from 1 to number of items in a_list
set a_file to (item i of a_list)
try
set {name:Nm, name extension:Ex} to (info for a_file as alias)
set fileName to text item 2 of Nm
set baseName to text 1 thru ((get offset of "." & Ex in fileName) - 1) of fileName
tell application "Finder" to set name of a_file to delimiter & baseName & "." & newExtension --> rename the file
end try
end repeat
set text item delimiters to TID
One thing, while I am not totally sure exactly how this script works because I am fairly new to this.
I need the script to also remove the “.tif” that is at the back of the name:
belts_0000s_0005_W102BT00.tif.jpg — end result being W102BT00.jpg
Also, I have this saved as an application so that files can be dragged onto it. What I have figured out is that in order to do that, it does not like global properties. I may be wrong, so if there is a way please let me know.
this script can be launched normally and works also as a droplet.
It removes the .tif extension, if there is one
property delimiter : "W"
property newExtension : "jpg"
on run
set chosenFiles to choose file with multiple selections allowed
open chosenFiles
end run
on open droppedFiles
set {TID, text item delimiters} to {text item delimiters, delimiter}
repeat with i from 1 to (count droppedFiles)
set a_file to item i of droppedFiles
try
set {name:Nm, name extension:Ex} to (info for a_file)
set fileName to text item 2 of Nm
set baseName to text 1 thru ((get offset of "." & Ex in fileName) - 1) of fileName
if baseName ends with ".tif" then set baseName to text 1 thru -5 of baseName
tell application "Finder" to set name of a_file to delimiter & baseName & "." & newExtension --> rename the file
end try
end repeat
set text item delimiters to TID
end open