Simple file-naming tool


First of all I’m happy that I found this forum, I’m totally new to Apple Script, to be honest- today is my first day when I saw possibilities of it. I hope to learn something new.

I tried to look for solution but each thread which I found is doing extra tasks- unnecessary for me.

I need simple Automator Quick Action which will work with Finder folders.

What it should do- rename files inside folder using folder’s name and add prefix- 01, 02, 03.

For example, when I start it on folder named “Folder1” all files inside (photos) should have their name changed to “folder1_01.jpg”, “folder1_02.jpg”. There won’t be any subfolders in it, all files will be .jpg

I tried to change scripts which I found but without any success- I also tried “A Better Finder Rename” but it don’t have option to completely change filename to name of the folder.

Maybe anyone was doing it and can share script with me?

Thank you in advance for help!
Have a great day!

Hi Michass. I’m new to these forums too, and athough I have a little bit of practice with AppleScript, I’d say I’m probably still a novice. But I think I can help. Maybe. Looks as if newbs like us might have to look out for each other :wink: so I’ll give it a go. Your request is pretty straight forward, but, things sometimes have a tendency to become much less easy than they first appeared. Especially with as little practical knowledge as I have hehe. Anyway…

I know we’re in the Automator forum, but we should find out if you really need to use Automator for this, or if some other way will suffice. There are a number of ways to net your desired result e.g. create a Folder Action, or an Automator Service etc. And each different way will have it’s own crap to deal with. IMO it’s better to approach the task in as simple a way as possible first. That way, if a solution is found we save ourselves from getting stinky messing with all that unnecessary crap.

The simplest way, probably, would be for you to have a script saved as an application, and kept somewhere close to where all the folders full of pictures are. The folder where those folders are kept would be perfect.

Here’s a little script you would simply double click to rename the files of a chosen folder, all with your specified parameters. This is my first time posting a script so, you might wanna step back - maybe have a fire extinguisher at the ready…

--select the folder to go to work on
set trgtDir to (choose folder)
--estasblish a numeric ID
set countR to 1

tell application "Finder"
--get the name of the images' parent folder
	set baseName to name of trgtDir
--bring Finder's attention to the intended images
	set theFiles to trgtDir's files
--we'll use a repeat loop to iterate through each of the images, renaming as we go
	repeat with thisFile in theFiles
--let's augment their new names with the numeric ID we established earlier
		set newName to baseName & "_" & countR
--and then rename the image file
		set thisFile's name to newName
--then make sure the next one doesn't get the same name
		set countR to (countR + 1)
	end repeat
end tell

And that’s it… hopefully. If something goes wrong, I’m certified to administer CPR so just PM me or something… :stuck_out_tongue: