Hello MacScripter Community,
I have searched for a long time but can’t find posts to help me accomplish what I need to do specifically.
I have an ongoing project where I have to manually sort photos into a folder of sub-folders. This folder structure is constant. After I sort them, I would like to use Applescript to change file names then move them to a single folder, “00-Complete”. I’m adding an example below.
Basically, I need to remove the first 7 characters of each file name then add “_01, _02, _03” etc. to each file within it’s respective sub-folder so they remain in the same sort order. Then move them to the “00-Complete” folder.
Try this, you will be prompted to select the parent folder of the image folders
set baseFolder to choose folder
tell application "Finder" to set imageFolders to folders of baseFolder
repeat with aFolder in imageFolders
if name of aFolder starts with "00" then
set completeFolder to contents of aFolder
else
set prefix to text 1 thru 2 of (get name of aFolder)
tell application "Finder" to set allImages to files of aFolder
repeat with aFile in allImages
tell application "Finder" to set {name:fileName, name extension:fileExtension} to aFile
set baseName to text 1 thru ((get offset of "." & fileExtension in fileName) - 1) of fileName
set newName to text 8 thru -1 of baseName & "_" & prefix & "." & fileExtension
tell application "Finder"
set movedFile to move aFile to completeFolder
set name of movedFile to newName
end tell
end repeat
end if
end repeat