rename jpgs

hi,
i´m looking for a script or automation, which renames jpgs to the name of the folder they are dropped in by me.
it should be kind of a folder action, so that i can create a folder called e.g. xyz and as soon as i drop pics in it, they are renamed to xyz_001.jpg etc…
is there anything like that?

thanks
pms

Model: mac os x
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Have you tried writing one yet?

Hi,

I wrote something like that a few months ago as a droplet.
The files will be sorted by creation date and renamed the way you described.
The number of leading zeros depends on the number of files in the folder

on run
	set thefolder to (choose folder with prompt "Choose folder")
	RenameFolder(thefolder)
end run

on open rename_folders
	repeat with thefolder in rename_folders
		RenameFolder(thefolder)
	end repeat
end open

on RenameFolder(thefolder)
	set ItemsList to {}
	set {isFolder, foldername} to {folder, name} of (info for thefolder)
	if isFolder then
		tell application "Finder"
			set ItemsList to document files of thefolder
			set FileList to sort ItemsList by creation date
			set FileList to reverse of FileList
		end tell
		set ItemCount to count FileList
		set TheNumber to 1
		
		repeat with cFile in FileList
			set Ext to name extension of (info for (cFile as alias))
			set NumberString to TheNumber as string
			set LeadZeroCount to ((count ItemCount as string) - (count TheNumber as string))
			repeat LeadZeroCount times
				set NumberString to "0" & NumberString
			end repeat
			set NameString to foldername & "_" & NumberString & "." & Ext
			tell application "Finder" to set name of cFile to NameString
			set TheNumber to TheNumber + 1
		end repeat
	end if
end RenameFolder

hi stefan,
perfect!thanks a lot! exactly what i was looking for!
i´m a total script.- and folder-actions beginner… can i ask you another thing:
what do i have to do now, so after creating an emptyfolder, so that in the moment i drop pics in, the script starts?

oder auf deutsch:
was muss ich machen, damit ich einem ordner dieses script zuweisen kann-damit das script oder die aktion selbsständig starte sobald bilder in den ordner bewegt werden?

vielen dank nochmals

peter

Hi Peter,

considering of the others let’s keep the conversation in english :slight_smile:

It’s easy to add an folder action handler to the script,
but there’s a big problem with renaming scripts attached to a hot folder.
At the moment the file will be renamed the action handler regards it as a new file
and restarts the renaming process. This causes an infinite loop.
So it would be better to use a droplet or to move the files out of the hot folder before renaming them

hi stefan,
such a droplet sounds quite useful! so what would i need to do please? do i create it with automator or with the scripteditor?

thanks sooo much

peter

Hi Peter,

my script above is a droplet.
So save it as an application and drop folder(s) onto it.
The contents of each folder will be renamed separately

hi stefan,
i figured the droplet out myself! thanks anyways.
one more question: is it possible, that it creates always 3 digits for the count of files?
thanks

peter

of course, this is much easier than calculate the length,
here the handler

on RenameFolder(thefolder)
	set ItemsList to {}
	set {isFolder, foldername} to {folder, name} of (info for thefolder)
	if isFolder then
		tell application "Finder"
			set ItemsList to document files of thefolder
			set FileList to sort ItemsList by creation date
			set FileList to reverse of FileList
		end tell
		set TheNumber to 1
		repeat with cFile in FileList
			set Ext to name extension of (info for (cFile as alias))
			set NameString to foldername & "_" & (text -3 thru -1 of ("00" & (TheNumber as string))) & "." & Ext
			tell application "Finder" to set name of cFile to NameString
			set TheNumber to TheNumber + 1
		end repeat
	end if
end RenameFolder

thanks stefan! runs perfekt!
peter