Script to put files in correct folders automatically?

I generate a fair amount of radio copy for several different clients every week. I keep the files organized in my Current Projects folder by giving them a three letter prefix that identifies the client. I’d love to create an AppleScript or Applet that I could drop the files onto when they’re no longer active that would file them automatically in the correct archive folder. I figure I need a script that reads the prefix and moves the file to the corresponding folder. Where do I begin in creating something like that? (I’m running full time in OS X v10.2.3, by the way.)

tell application "Finder"
	set myFolder to choose folder
	set mylist to list folder myFolder without invisibles
	set myFolder to myFolder as string
	repeat with i from 1 to count mylist
		set this_item to item i of the mylist
		set this_item to ((myFolder) & this_item) as alias
		set thisinfo to info for this_item
		if name of this_item begins with "abc" then
			move this_item to folder "ABC"
		else if name of this_item begins with "def" then
			move this_item to folder "Def"
		end if
	end repeat
end tell

of course you will have to replace the ABC with your prefix and your folder name
and def with your prefix and folder name and add any others if needed

This might work. I tested it with OS X 10.2.3 and it seems to do what you want. You’ll need to provide a path to the target folder and the prefix in the first two lines of the script. Then save the script as an application. If it works, you can use it as a template to create a script for each client (easier) or modify it so that it will handle all clients (harder but not too bad). :slight_smile:

property targetFol : "path:to:target:folder:"
property prefix : "abc" -- unique prefix (three characters)

on open droppedFiles
	repeat with thisFile in droppedFiles
		tell application "Finder"
			set fileName to name of thisFile
			if text 1 thru 3 of fileName is prefix then
				move thisFile to folder targetFol
			end if
		end tell
	end repeat
end open

The script should also be the recipient of some error checking routines to handle missing folders and stuff like that. This helps to avoid :cry:.

I have a question

How does the Property statements work

what do they do?

In a nutshell, properties are persistent variables. This means that the value can be modified during script execution and the modifications will stick until the next execution (or until the script is recompiled). In the script above, it isn’t really necessary to use properties since the value isn’t being modified by the script. When I used the properties, I had plans that required them, but I changed my mind and forgot to remove the properties. :stuck_out_tongue: