sorting Word files into one folder, Canvas files into another, etc.

Is it possible to use Apple Script to comb through your whole computer and stick all Microsoft Word files into one folder, all Excel files into another folder, all Canvas files into another folder, etc.? I’ll add two extra complications: 1. The files are not identifiable by suffix (e.g. Word files do not all end in .doc); and 2. there can be multiple different files with the same title (e.g. I download a PDF file of a scientific article and it’s automatically called “Science.PDF” by the journa. I want to keep all of these. If there is a PDF folder and my script sticks a document in there called “Science.PDF” and there’s already one in there with that name, then I want the Script to give the file a new name - like “Science_1.PDF” and then stick it into that folder).

Any help would be appreciated.



P.S. I think that the operating system for the computer I want to do this on is Panther, but it might be Jaguar. It’s definitely not Tiger.


It should be, but it will take some effort. If you run the script below on some of the files you are worried about, it will tell you the [kind] of the file you have chosen. That should work on nearly all (if not all) the files you want, regardless of the extension. With that information, you should be able to write a nifty script to sort everybody out.

set a to choose file
tell application "Finder"
	get kind of a
end tell

Renaming should also be simple. When your script finds a file that it wants to move, first have it check the name and then give it a new name if it already exists:

set a to choose file
set d_path to Your_Destination_Folder
tell application "Finder"
	set b to name of a
	set c to (d_path & b as Unicode text)
	if file c exists then
		set name of a to (b & "_02" as string)
	end if
end tell

I admit that I have not tested that second script, but it should work. If not, let me know and I can mess with it.

That should be enough to get your started. Once you have some code written, post it back here and a bunch of really smart people will look it over and help you out. I will look at it, too.

Craig Smith

Thanks, Craig! I’ll get to work on the script and post it here once I’ve figured out something that I think should work. It will probably take over a week, since I’m pressed for time now and I’m a complete novice at Apple Script, but I appreciate your solving what I expected to be the toughest parts of the process - especially the part about figuring out the file type without having the help of an extension.

Thanks again.