Consecutive Alphabet File Names

HI :smiley:

I’m new to AppleScripting.

I’m looking for a droplet that will rename a set of documents with a consecutive alphabet letter. For example,

I have exported a multipage document from InDesign as EPS. The resulting set of EPS files are named FileName_1.eps, FileName_2.eps, FileName_3.eps, and so on.

What I need to find is a script (preferably as a droplet) that will rename the documents as FileName_1-A.eps, FileName_1-B.eps, FileName_1-C.eps, and so on. I also need it to batch rename all files.

Thanks for your help?

I can think of a way but it would be a bulky script using a lot of “if” statements. Unless you have to do this often it might be easier to just do it by hand.

If you really want a script then I suggest setting up a variable that is a list of the names of every file of the folder, then setting a variable that increases by 1 for each loop, then a set of if statements saying “if myvariable is equal to 1 then set lettervar to A” etc.

Then tell it to “rename item x of filelist to (name of item x & lettervar)”

The only problem I can’t solve off the top of my head is how to get the additional letter to come before the extension but I’m sure there’s some way to get that to happen.

Filename 1.9 http://scriptbuilders.net/category.php?id=2120
is a script I wrote to tackle those huge batch file renames, as a droplet. Select a bunch of files, drop them, give a name, and a number to start the order. If it doesn’t know the windows extension (.jpg, .mpg) it will ask for that too. Superfast!

No problem. What if you have more than 26 documents in a batch?
FileName_1-A.eps-
FileName_1-Z.eps-
?
I suppose it would continue with FileName_1-ZA.eps … I’m sure there’s a better way but I’ll get back with script.
SC

One answer is to “parse the text”, get only the name: filename_01
Set the alphabet to a list; every letter then has an “item #”- A is item 1 in the list, B is item 2 in the list, and so on.
Set the counter to 1 and get a loop going, as you were hinting at. Here’s the trick: each time you need the next letter, its solved by the counter increasing with each loop, and returning the next letter in the list.
Put it all together with the statement-
set name of thisItem to JustTheName & item counter of Alphabet & “.eps”


--copy this into a new script editor window
--save as an application
on open filelist
	tell application "Finder"
		select filelist
		set theFiles to (sort the selection by name)
	end tell
	set Alphabet to {"-A", "-B", "-C", "-D", "-E", "-F", "-G", "-H", "-I", "-J", "-K", "-L", "-M", ¬
		"-N", "-O", "-P", "-Q", "-R", "-S", "-T", "-U", "-V", "-W", "-X", "-Y", "-Z", "-ZA", "-ZB", "-ZC", "-ZD", ¬
		"-ZE", "-ZF", "-ZG", "-ZH", "-ZI", "-ZJ", "-ZK", "-ZL", "-ZM", ¬
		"-ZN", "-ZO", "-ZP", "-ZQ", "-ZR", "-ZS", "-ZT", "-ZU", "-ZV", "-ZW", "-ZX", "-ZY", "-ZZ"}
	tell application "Finder"
		set counter to 1
		repeat with thisItem in theFiles
			set FullName to name of thisItem
			set AppleScript's text item delimiters to {"."}
			set JustTheName to the first text item of FullName
			set AppleScript's text item delimiters to {""}
			try
				set name of thisItem to JustTheName & item counter of Alphabet & ".eps"
			on error
				display dialog "This script can only alphabetize 52 files at a time."
			end try
			set counter to counter + 1
		end repeat
	end tell
end open

SiTCoM
:smiley:
Oh yeah, you said you were new to applescript; if you can’t get this saved as a working droplet post back and I’ll put the droplet of it in ScriptBuilders.

Thanks for all the replys to my post. I’ll try each of them. I have what I need for now.

after two days of searching, this is the closest ive seen to what I need to do. I need to do something similar, however instead of my list being the alphabet, I need to set my list from a text file (its a list of store numbers for a customer). I’ve found ways in my books to set a list to equal the contents of a text file, but I get an error whenever I try it " can’t set MapFiles to every word of mapnames2006.txt as string " or something like that. Any advice? I know this is a way old post, but hopefully bumping it will get some attention :slight_smile: Thanks!

Mark

Model: PowerMac G5 Dual 2ghz
AppleScript: 1.10.3
Browser: Firefox 1.5.0.1
Operating System: Mac OS X (10.4)

I suppose I should also mention that currently the files are jpgs generated from a 3002 page PDF, each file bearing the sequential page number its from in the PDF. The text file is composed of a list of six digit numbers seperated by a single space (I set it up like this thinking applescript could add by word) and the numbers are in the same order that they need to applied to the files. There are exactly 3002 files and 3002 six digit numbers… among other things could there be a limit to how many numbers (“words”) can be loaded into a list? Also, here’s a script I tried writing yesterday… I’m not very good at this yet… I’m using this task as a trainer for myself actually, so make fun of it all you want :slight_smile: :

set FileNames to (choose file) as string
set FileNamesB to (every word of FileNames) as string
set MapFiles to (every file of (choose folder))
display(MapFiles)
set CurNum to 1

repeat with CurFile in MapFiles
set FileNamesBNum to item CurNum of FileNamesB
–set MapFilesNum to item CurNum of MapFiles
set the name of item CurFile to FileNamesBNum
set CurNum to (CurNum + 1)
end repeat
end

I found it easier to have the script prompt me for the file and the directory it needs to work from, I kept getting errors about files that I knew were there being missing, so I figured this was an easier way for me to handle it. Any replies, advice, comments would be greatly appreciated. Thanks!

Mark