Rename from a list???

Hi, I have a lot of files to rename (image files .jpg). I would like to know if this is possible using a applescript or if anyone knows of any software that does this (from a list)

I have a folder located on my desktop containing the jpg files. I have an excel list of all the old file names and in the next column is their new file name. All that i need now is a script that will rename them!

Anyone any ideas - it’s been driving me nuts!!!

Thx in advance :slight_smile:

"Hi, I have a lot of files to rename (image files .jpg). I would like to know if this is possible using a applescript or if anyone knows of any software that does this (from a list) "

Sure, its in here. Select a batch of files by dragging your mouse over them, and drop them on to this script:
http://files.macscripter.net/scriptbuilders/Finder-System/FileName_X.sit

It will ask a name, number to begin, and order them by creation, first to last.

You can rename hundreds of files really fast. This part I’m not too sure about:

Is Excel scriptable? Why do you need it to rename jpg files? If you want to view the file before renaming or individually name them, thats another story. I’m working on a script right now that takes a list of jpg’s, opens one at a time, asks for a name, then closes it. It then shoots the next pic in the list onto the screen, and repeats till the list is done. This way you can individually name each pic in a huge list by simply typing the name and ‘enter’. If that sounds interesting let me know, I’ll post it.
SC

Thanks for your reply.

The reason for this is I have 1500 photos to assign to a database. The photo files are taken in alphabetical order but the file names are formatted from the camera mvc001.jpg etc The database will only reference the photo to the unique student id number

Therefore, I have an excel file with digital camera filenames in one column with the student id numbers in the next.

of course it doesn’t have to be an excel file - i could get it in a plain text file or csv if this makes it easier???

Any more ideas? your help is much appreciated. :slight_smile:

Hi,

In this simple script, I used an Excel file with these entries:

Picture 1.pdf MyPDF1.pdf
Picture 2.pdf MyPDF2.pdf

There are no field labels. Here’s the script:

set pic_folder to (choose folder with prompt “Choose the folder with pictures:”)
set excel_file to (choose file with prompt “Choose the Excel file:”) as string
tell application “Microsoft Excel”
Activate
Open excel_file
set d_range to (UsedRange of Worksheet 1)
set the_data to Value of d_range
end tell
repeat with this_list in the_data
set {old_name, new_name} to this_list
try
set file_ref to (“” & pic_folder & old_name) as alias
tell application “Finder” to set name of file_ref to new_name
on error – file not found
– do nothing
end try
end repeat

You can add error checking if you like.

gl,

My shareware application Name those Files! allows you to use a list from a text file for renaming batches of files. (Just save your names from Excel as a text file.)

Jon

The process you are looking to “automate” is easily done with applescript. It’s always best to have a script built for exactly what your purpose is. If the above tips don’t work out, post back and I’ll write a custom script for ya :wink:
SC
On the note of a cutsom script,

<—You should be able to read this without opening the actual text file
Reference:http://bbs.applescript.net/viewtopic.php?t=10904

Thanks for all your replies.

The scripts work well but to be really cheeky is there a way of specifying which folders and text file to look at since this unfortunately is not one big batch job!!!

The reason for this is all the students are allocated to class groups. So i have to export the photos by class group (into seperate folders located on my desktop) and then i have a list of the students database id numbers by class group save as seperate excel files (could be easilt converted to text files)

So for true automation i would like the script for me to run, ask me for the folder name and path and then ask me for the reference text fle or excel file, then run the rename.

Is this possible??

Many thanks again. :slight_smile:

I’m starting to narrow down the parameters of what your trying to do. Renaming from the list(s?) is no problem. I just have to figure out exactly what the variables are:

You say you have “a” list (singular) of the student id numbers by class group saved as “separate excel files” (plural).

:arrow: Is there 1 list or 4 (Freshman, Soph, Jun, Sen?)lists?

:arrow: Is there 1 Folder containing all the pics, or do they get sorted into classes immediately?

When you ran the PDF example code, did this not let you specify both?


set pic_folder to (choose folder with prompt "Choose the folder with pictures:")
set excel_file to (choose file with prompt "Choose the Excel file:") as string 

That should have let you choose any folder, and choose any file. That’s also why I’m wondering how many ID lists there are. Take a little time and make sure you explain every step so that we are on the same page.

“I can only give what is asked for…” AppleScript proverb

:slight_smile:
sc

Sorry - got myself all confused there!! (Working on this for too long!) :shock:

Yes - this is brilliant and I can get my system to work with this

However i get this error when i run it???

The variable d_range is not defined.

Any ideas - and many thanks for your help. :slight_smile:

The thing about AppleScript that gives people the most trouble is each application has its own dictionary, and if things aren’t exactly as the script is told they should be, it won’t work. To check your error, make sure you use the same “format” as Kel did for your lists. The format used was an excel file with no field labels:
Picname(space)StudentIDnumber
Picname(space)StudentIDnumber
Picname(space)StudentIDnumber
If your lists aren’t in the same format, you’ll get errors or undesired results.
Notice also the requirement that “there aren’t any field labels”. Got that?
As for the error “The variable d_range is not defined.”, look at the script lines

Open excel_file
set d_range to (UsedRange of Worksheet 1)
set the_data to Value of d_range

In this case “(UsedRange of Worksheet 1)” is not understood by the script. Tracking down the returned value for (UsedRange of Worksheet 1) will give a clue to the error.
But you just want the thing to work, not learn AS, right!!! :shock:
I would suggest sending Kel a PM and asking for some pointers.
SC

If there aren’t any field labels, how can the UsedRange be determined? Arrrrg

Yes, selecting the range seems to be the problem. Does anyone know where i can get some info on scripting within excel or could give me some pointers???

Or…Would it be easier to use a plain text file??? (If so, how would this be done?)

Sorry for all the questions - you may have guessed…but i am new to applescript (you don’t say - i here you cry!!!)

This is a great forum and thanks for all your help!

Getting a bit further now!!! :smiley:

I have replaced this part of the script:

Open excel_file
set d_range to (UsedRange of Worksheet 1)
set the_data to Value of d_range

to

Open excel_file
set d_range to (used range of sheet 1 of active workbook)
set the_data to value of d_range

This gets me further but now i get the error message:

Can’t get item 2 of {“5431.jpg 5450036”}.

5431.jpg is the photo 545003 is the databse id (new file name)

Any ideas???

I’m working on this, and it’s pretty easy. You dont have to even open the Excel file to read it!


set prefContents to (read (choose file))'s paragraphs as list

Returns
{“5431.jpg 5450036”, and all the rest of the photonames and student ids}.
What you need to know is what a delimiter is. What separates .jpg from 545 above?It looks like a space, but its a tab!!! That means the two items are “tab delimited”, separated by a tab. “space delimited” means separated by a space. If you set the delimiter to space when its a tab, youre done for!
:arrow: The file needs to be saved as a .txt file, this gives you
photo1.jpg 109100
photo2.jpg 109101
photo3.jpg 109102
Now we have to break down that to a list


set prefContents to (read (choose file))'s paragraphs as list

and you get
{“photo1.jpg 109100”, “photo2.jpg 109101”, “photo3.jpg 109102”}
set the text item delimiters to “,” to get
photo1.jpg 109100
set the text item delimiters to " " to get
photo1.jpg

And finally, if photoname matches photoname in id list, set photoname to photoname in id list.
Thats the basic idea.
thats why you get errors, your delimiters are off!
I’m building
SC

Thanks SC - that sounds great! :smiley:


set the_list to (read (choose file with prompt "Choose the file that contains the student ID's:"))'s paragraphs
set source_folder to (choose folder with prompt "Choose the folder with the .jpg's to rename:") as Unicode text
tell application "Finder"
	repeat with this_para in the_list
		set {source_file, new_name} to my string_to_list(this_para, tab)
		try
			set name of ((source_folder & source_file) as alias) to new_name & ".jpg"
		on error e
			activate
			display dialog e buttons {"Cancel", "OK"} default button 2 with icon 0 giving up after 5
		end try
	end repeat
end tell

on string_to_list(s, d)
	tell (a reference to my text item delimiters)
		set {o, contents} to {contents, d}
		set {s, contents} to {s's text items, o}
	end tell
	return s
end string_to_list

Wow, that simple?

That should do it. Thanks to jonn8 out of NY who wrote this code (who has a shareware application Name those Files! See his post above, support him if you can). I’m going to compile it and put it in code builders for future users (minus the Student ID dialog). I’m sure you can get this to work for you now though. The cool thing is the Excel file never opens; Everything is read and set “behind the scenes”. Remember, the script is custom built and relies on a “Tab delimited text file”. It can be a .txt document from any application.

Now get to work!!! :lol:

This is great - it is working brilliantly. Thank you all very much :slight_smile:
Just another 1470 photo’s to go!!! :shock:

For anyone else who is looking to use excel to do this or a similar task, if you save the file to be a .csv file the delimiter then becomes a comma in place of a tab.

Therefore change this line of the code from:
set {source_file, new_name} to my string_to_list(this_para, tab)

to:

set {source_file, new_name} to my string_to_list(this_para,“,”)

So now i can use Excel which saves me even more time!!! - Thanks again :slight_smile:

We hope you’ve learned a lot about AppleScript and maybe even a little about yourself :lol:
SC