Rebuilding File Extensions

Ok so files on mac dont have to have file extensions, in fact nearly all applications actually dont defaultly save an extension onto the file or the file data.

I did a get info for alias on file names who have no extensions, and the name extension property returns as empty so I cant rebuild it from there.

Is there any system library that detects what applications have which type of extensions to rebuild them? I need to beable to read this data to set file icons in a flash based application to the appropriate type.

Regards,
Robert

Hey xfuzion,
Here’s a program that will change a limited number of files to their correct extensions. I used the ‘kind’ property that every file has, and the program goes through a list of the kinds and adds the correct extension to the file (which is found in another list). There’s probably a MUCH more efficient way to do this, yes, but at least this works.

tell application "Finder"
	set thefolder to folder "path" of folder "to" of folder "the" of folder "folder"
	set kindList to {"Application", "Microsoft Word document", "JPEG Image", "PDF Document", "AIFF Audio", "Microsoft PowerPoint document", "MIDI File", "script", "TIFF Document", "Microsoft Excel workbook", "Portable Network Graphics Image", "Graphics Interchange Format Image"} --These are the kinds
	set extList to {".app", ".doc", ".jpg", ".pdf", ".aiff", ".ppt", ".mid", ".scpt", ".tiff", ".xls", ".png", ".gif"} --These are the extensions that go with the kinds. Notice they're in the same order.
	repeat with theItem in thefolder
		set k to kind of theItem
		if name of theItem does not contain "." then --Sometimes extensions are really there and just hidden.
			repeat with i from 1 to number of items in kindList
				if k is (item i of kindList) then set name of theItem to (name of theItem) & (item i of extList)
                             --Go through each item of kindList and check to see if the file is that kind. If it is, append the file name with the extension in the same place in extList.
		       end repeat
		else
			set extension hidden of theItem to false 
		end if
	end repeat
end tell

You’re going to have to go through and add the kinds and extensions that you’re going to use. You can get this easily by using this:

 tell application "Finder" to get kind of every file of folder "path" of folder "to" of folder "the" of folder "folder"

Just make sure the kinds and extensions are in the same order.
EN