add file extension?

Hi,

Sorry, I am useless when it comes to this stuff but I have tens of thousands of images (.eps. .jpg, .tif, etc.) all of which need file extensions added. I searched the archives and found that many people have asked this question and plenty have answered but nothing I tried worked for me. Maybe it is because the answers assume a certain level of knowledge? In any case, can someone help me with this? I would like it to be able to ask me to locate the folder with the files and then chug through and add the file extensions. Please!

Thanks very much.

This will rename files and add the extension.

Regards,

Craig


tell application "Finder"
	activate
	set theSelection to choose folder with prompt "Select the folder containing the items you wish to rename."
	set theSelection to every file of theSelection
	
	set nameExtension to my getUserResponse("Enter extension name only, ex. pdf, not .pdf", {"Cancel", "Ok"}, "pdf")
	
	repeat with i from 1 to count the theSelection
		set thisItem to item i of theSelection as alias
		set currentName to name of thisItem
		set newName to currentName & "." & nameExtension as Unicode text
		set name of thisItem to newName
	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

Hi Craig,

Thanks very much – that worked beautifully! But… in a perfect world I would like the script/Mac to be able to figure out what the file extension should be without me having to tell it. Is that possible? If not I know I can just sort by file type and do folders full of like files instead of all at once. That’s certainly easy enough. Thanks again.

You can get the extension using the following.


set nameExtension to name extension of thisItem

Run this script on several files and tell me the results you get.
I want to make sure you are getting extension names.


tell application "Finder"
	set chooseFile to choose file without invisibles
	set nameExtension to name extension of chooseFile
	display dialog nameExtension
end tell

Regards,

Craig

Hmmm, neither of those short scripts did anything. Am I supposed to add them to the larger one you gave me earlier? Thanks.

So when you ran the second script there was nothing
in the dialog?

Craig

Hi jenwaddell,
If you double click on the .eps. .jpg .tif, etc, that do not have extensions, do they open?
If so, what application(s) do they open in?

Tom

Operating System: Mac OS X (10.4)