newbie help - script for organizing files

Hi there.

this is my first steps working with applescript. im trying to write a script which organizes files in a folder depending on file type (name extenstion).

here is what i got sofar:

tell application "Finder"
	
	set imageType to {"jpg", "tiff", "psd"}
	set audioType to {"mp3", "wav"}
	set videoType to {"mov", "avi", "wmv", "mpeg", "mpg"}
	-- other filetypes to be added here...

	set allFiles to every document file of folder "example"
	
	repeat with oneFile in allFiles
		try
			set fileType to name extension of oneFile
			if imageType contains filetype then
				move oneFile to folder "Images" in folder "example"
			else if audioTypes contains filetype then
				move oneFile to folder "Audio" in folder "example"
                     else if videoTypes contains filetype then
				move oneFile to folder "Video" in folder "example"
			end if
			
		end try
	end repeat
	
end tell

Is there a way to optimze this code usnig records or lists so i need only one search query and get the destination folder?

Hello Jaques. Thank you for helping so quickly.
I am now trying to construct an efficient folder action script for organizing my downloaded files.


on adding folder items to this_folder after receiving these_items
	
	...
	
end adding folder items to

i guess in this case it is better to process each file one at a time.
any suggestion of how to implement this efficiently?
also, is there an irc channel where macscripters meet and chat?

Browser: Safari 416.12
Operating System: Mac OS X (10.4)

Hello Jaques,

i dont quite understand how to get that “folderactionreplacement” working. Is it just like a separate application which always needs to be running?

I found this script here which seems to be working fine for me right now:

http://bbs.applescript.net/viewtopic.php?id=9848

havent tried it with bigger files though…

Greetings :cool: