Dynamic Rename Folder Action

:slight_smile: Hi everyone, I’m new to Automator and I have a situation thats boggling my mind!:

I’ve been looking for a way to dynamically rename files using Automator. I am having problems using the built-in rename action Automator has.
When the standard Automator re-name action is used as a folder action to re-name files sequentially when they are dragged into a certain folder, instead of renaming the newly dragged-in file according to the sequential run, it re-names every file in the folder not just the new one.
The effect is that everything is jumbled up. I’d be so grateful if anyone could offer me some advice on this. I’ve heard mention that a shell script could provide an answer(?) but I’m not sure how that works with Automator. Pleeeease help!:o Thanks

Model: 2004 1.5 GHz Powerbook G4
Browser: Firefox 1.5.0.1
Operating System: Mac OS X (10.4)

It’s not a good idea to rename items in a folder with a folder action. Unfortunately, the new name makes the file new again, and the action does weird things. If you’re going to rename these files, better to move them first to a holding folder, rename them there, and leave them there. You need two folders: “Drop 'em here” and “Renamed here”.

Hi Adam thanks for the reply.:smiley:

I see what you mean about the folder action route and you’re right. The trouble is I need the images to rename according to a filename sequence. The files themselves will be added to the folder one at a time (uploaded to the Mac via bluetooth) and because I’m not batch renaming the files the folder needs to recognise where the end of the sequence is so it can rename the new one correctly.

Am I right in thinking this type of renaming requires an Applescript that can track changes to a folder or has some kind of conditional programming? I’ll give what you suggested a try anyhow and let you know if works out.:slight_smile:

You don’t say how the filename sequence is generated, but if it’s just first in = lowest number, subsequent files numbered consequtively as they appear, then when a file is dropped on the “Drop Here” folder, the script attached to that folder moves it to the other and then renames it. Finding the appropriate sequence number is a matter of finding the youngest file in the storage folder.

I use this to do that:

set theFolder to choose folder with prompt "Select anything for this example"
tell application "Finder"
	-- get the latest file (check to see whether the -1 should be a 1)
	-- This depends on which way it is sorted by the Finder. The opposite sign will be earliest.
	set theFile to (item 1 of (sort (get files of folder theFolder) by modification date))
	-- Convert the finder reference to it to a path
	set thePath to theFile as string
	-- get its name
	set theName to name of theFile
end tell
display dialog "The complete path: " & return & thePath & return & return & "The Name of the file: " & theName

Hi there,
Thanks for that script, it does the job of identifing the youngest file in a folder which looks like the first step to renaming it. The sequence I am using is:

img_01.jpg
img_02.jpg
img_03.jpg
img_04.jpg

I am also using Automators default rename functions and attaching that workplow as a folder action. Currently ithe workflow looks for jpg files in a folder, renames them all in the sequence above, then comes the problem whioch I’ve described already of renaming only the youngest file to the fit the sequence. In reality I am starting with only one file in the folder as a reference i.e. “img_01.jpg”. All new ones must be in sequence once dragged in.

Do you think there is a way of building upon the script you have recommened? Perhaps having the output of the youngest filename being the subject of a rename? Is it possible to use a txt file with the entire sequence that the applescript can refer to to rename a file?
The script you posted is almost perfect. I see how you have done it though I am not well versed in the applescript language. Once again thanks for your efforts!:slight_smile: