Hi there.
Can someone please tell me how to create an applescript that will rename a bunch of files by re-arranging the text that is already in the name. For example, a script that will rename 1234-henry-231066 to 231066-henry-1234 and do this for all the files in the folder?
Or perhaps you know of a script/application that has already been written… that would be better.
Thanks
This is slightly clunky, but it will do the job, as long as the pattern of all the filenames is the same, that is, there is a string, a dash, a second string, a dash, a third string, and then the file extension. It is set up now to just do a single, chosen file, but could be easily set up to process an entire folder.
set a to choose file
tell application "Finder"
set b to (a's name)
set a's name to my SwapFilename(b)
end tell
to SwapFilename(fn)
set fnWords to every word of fn
set newName to (fnWords's item 3) & "-" & (fnWords's item 2) & "-" & (fnWords's item 1) & "." & (fnWords's item 4)
end SwapFilename
Thank you very much for this. I am a little clunky myself when it comes to Applescript… how could this be changed to select and process an entire folder.
Again… many thanks.
Here is a slight modification so that it will process every file in the chosen folder:
set a to choose folder
tell application "Finder"
set all_Files to (every file of folder a)
repeat with each_File in all_Files
set b to (each_File's name)
set each_File's name to my SwapFilename(b)
end repeat
end tell
to SwapFilename(fn)
set fnWords to every word of fn
set newName to (fnWords's item 3) & "-" & (fnWords's item 2) & "-" & (fnWords's item 1) & "." & (fnWords's item 4)
end SwapFilename
I am trying to make it into a droplet, but am having difficulties. If I can figure it out, I will post that as well.