automating sorting of folder contents

I wrote this script to sort the files in my “downloads” folder

set ifolder to path to downloads folder from user domain
set imgfolder to "Leopard:Users:oneonly:Downloads:Images"
set pdffolder to "Leopard:Users:oneonly:Downloads:pdf"
set appfolder to "Leopard:Users:oneonly:Downloads:app"
set automatorfolder to "Leopard:Users:oneonly:Downloads:app:Automator Actions and Workflows"
set appext to {"dmg", "mpkg", "pkg", "app"}


tell application "Finder"
	move (every file of ifolder where name extension is "png") to imgfolder
	move (every file of ifolder where name extension is "pdf") to pdffolder
	move {every file of ifolder where name extension is item {1} of appext} to appfolder
	move (every file of ifolder where name extension is item {2} of appext) to appfolder
	move (every file of ifolder where name extension is item {3} of appext) to appfolder
	move (every file of ifolder where name extension is item {4} of appext) to appfolder
	move (every file of ifolder where name extension is "action") to automatorfolder
	move (every file of ifolder where name extension is "workflow") to automatorfolder
	
	
end tell

As you see, i have repeated “move” command for each of the four items in the list “appext”. How do i avoid it?
(I still have to add several extensions)

Secondly, how do i automate it-------i mean, every item ,a file is placed in “downloads” folder, the script should run automatically. (I guess, it requires suitable modifications to be used as a “Folder actions” script.)

Lastly,
if a folder contains a file with extension “app” then i would also want that entire folder to go to "“Leopard:Users:oneonly:Downloads:app”
can it be done?

I have not fully tested the code here, it does compile (though I had to make a substitute for downloads folder, since that does not exist in 10.4).

One method is to use a list of records. Each records represents a category of files. It holds a list of extensions (exts) that qualify the file for that category and the destination folder (dest).

set ifolder to path to downloads folder from user domain
set imgfolder to "Leopard:Users:oneonly:Downloads:Images"
set pdffolder to "Leopard:Users:oneonly:Downloads:pdf"
set appfolder to "Leopard:Users:oneonly:Downloads:app"
set automatorfolder to "Leopard:Users:oneonly:Downloads:app:Automator Actions and Workflows"
set moveList to {{exts:{"png"}, dest:imgfolder}, {exts:{"pdf"}, dest:pdffolder}, {exts:{"dmg", "mpkg", "pkg", "app"}, dest:appfolder}, {exts:{"action", "workflow"}, dest:automatorfolder}}

tell application "Finder"
	repeat with moveItem in moveList
		move (every file of ifolder where name extension is in (exts of moveItem)) to (dest of moveItem)
	end repeat
end tell

Yes, Folder Actions are the likely route for this. The code will be a bit different though. For example, the list of new items will be provided, so you do not have use every file of ifolder. Also, where can not be applied to lists such as the one you will be provided with in a Folder Action handler. You would have to loop through each item in the list and apply a the tests to it “by hand”. Search for Folder Action scripts around here, and in the AppleScript examples and see what you can come up with.

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari Version 3.1.2 (4525.22)
Operating System: Mac OS X (10.4)

works fine. thanks chrys

i will look around and then post here