Batch renaming files on network drive

Hello everyone

This is a newbie question - I’m really new to MacOSX (Leopard), but I like it a lot, and I want to use it to it’s full potential, so I decided to dive into Automator.

Using this link, I composed a batch rename automator action. The sequential numbering does work, but giving the files a new name does not work: I end up with files that are called “-001.jpg”, instead of “Holiday-001.jpg”. The automator action does not take the new filename into account - unless if I specify it before I save the autmator action, but I cannot give any other name to the file.

At first I thought it had something to do with the files being on a network drive, but files that are located on my Macbook have the same outcome.

Thank you for your help.
Ann

Model: Macbook
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)

Hi Ann,

Welcome to the Mac community!

I played around with the Automator action and had
interesting results. Every time I ran the action it would
rename the files based on the value of the previous run.
It was not taking into account the new value for name.

If you don’t mind using AppleScript I can put one together
that will do what you are wanting to achieve.

A few questions:

  1. Do you always want to name the files the same name
    or sometimes just add a sequential number to the existing
    file names?

  2. Would you ever want the number to be at the beginning
    of the name instead of the end?

Cheers!

Craig

Hello Craig

Thank you for your reply and your kind words.

I wanted to use the script on pictures I imported from my digital camera. Since I already have a filesysystem for my digital pictures, I did not want to move my pictures physically to my iPhoto library. So I move them manually (even though that does not always work good - there are always some pictures that seem to be used by the computer, even though all I did was just opening the finder - but that is another story) to the network drive, but then I want to rename them, so that the name from the picture tells a bit more than just ‘IMG_5980.jpg’, so that’s where the numbering and the name comes in.

I really prefer to rename them, and have the name first, followed by the number. Normally I want the number to follow the name, and I always want to rename them.

Thank you for your help.
Ann

Hi Ann,

If you save this script as an application you will only need to double-click it to
activate.

The script allows you to either select a group of pictures or choose a folder containing
pictures. It asks for a starting number and then a name. When you click ok all the pictures
will be renamed and numbered.

If you have any questions, let me know.

Hope this helps!

Craig


property numberDelimiter : "-"

tell application "Finder"
	activate
	set theSelection to the selection
	if (length of theSelection) < 1 then
		set theSelection to choose folder with prompt "Select the folder containing the pictures you wish to rename."
		set theSelection to every file of theSelection
	end if
	
	set theNum to my getUserResponse("Enter start number?", {"Cancel", "Ok"}, "1")
	set theName to my getUserResponse("Enter new name?", {"Cancel", "Ok"}, "")
	
	set theCount to theNum
	repeat with i from 1 to count the theSelection
		if theCount < 10 then
			set theCount to 0 & theCount as string
		end if
		set thisItem to item i of theSelection as alias
		set currentName to name of thisItem
		set theItems to my tidStuff(".", currentName)
		--set thisName to item 1 of theItems
		try
			set thisExt to ("." & item 2 of theItems) as string
		on error
			set thisExt to ""
		end try
		set newName to theName & numberDelimiter & theCount & thisExt as Unicode text
		set name of thisItem to newName
		set theCount to theCount + 1
	end repeat
end tell

on getUserResponse(theMessage, buttonList, theName)
	activate
	set userResponse to (display dialog theMessage default answer theName buttons buttonList default button 2)
	set fileName to text returned of userResponse
	set theButton to button returned of userResponse
	if theButton = "Cancel" then error -128
	return fileName
end getUserResponse


on tidStuff(paramHere, textHere)
	set OLDtid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to paramHere
	set theItems to text items of textHere
	set AppleScript's text item delimiters to OLDtid
	return theItems
end tidStuff

Thank you very much for your help, I’ll look into it tonight and tell you how it worked. I was already wanting to start with applescript, but I’m a bit scared, I have no knowledge of programming at all, but it sure seems to help to ‘unlock’ some real power of the Mac.

Edit: I used the script and it works very good, thanks a lot. Is it also possible to make the scirpt so that you can select some files?