Autofile - Watch Folder / AppleScript Help

Please excuse me as this is my first post. Hopefully, I am following protocol :smiley:

I am trying to figure out how to script something to save my wrist. I have a filing system that is based on characters.

For example:
First, based off the first two characters, then within the two character folder structure, three character folders.

  1. My file names are “993_NameOfFile”. Where 99 equals a specific category, and 3 equals a subcategory.

  2. So, using this example, my folders start 88, 89, 90, 91. etc until 99. Then within “99 folder” we have 991, 992, 993, 994, 995. etc.

So, the path for this file would need to be (Drive/99/993/993_NameOfFile). Understand?

More Examples:
645_CarDriving Drive/64/645/645_CarDriving
648_CarRed Drive/64/648/648_CarRed
754_GrassEarth Drive/75/754/754_GrassEarth
754_GrassMars Drive/75/754/754_GrassMars
755_ChiliRecipe Drive/75/755/755_ChiliRecipe
764_MushrmSoup Drive/76/764/764_MushrmSoup


How I am trying to get this to work is through a “watch folder.” During the day, I go through a lot of files, and need to place them at end of day (or when I need a break), into the watch folder so they automatically get placed into the folders and subfolders. I know there is a way to script this, but I don’t know exactly how on a mac?

On a PC I know I would need to have a script look for the first 2 characters of the file find that matching folder place the file in it, then, within that folder relook at the file for the first 3 characters and place it inside the matching 3 character folder.

Any help at all would be much appreciated and my wrist would thank you as well, as I am hand placing these 100’s of files daily.

Sincerely,
anickmator

anickmator:

Not quite the same thing, but the script I am working on has the necessary triggers for doing what you want:
http://macscripter.net/viewtopic.php?pid=139223#p139223

Looks like a few others have done things even closer to what you want:
http://macscripter.net/viewtopic.php?id=27615
http://macscripter.net/viewtopic.php?id=35502
http://macscripter.net/viewtopic.php?id=34835
http://macscripter.net/viewtopic.php?id=34633
http://macscripter.net/viewtopic.php?id=33963

I would consider going so far as setting the script up to read the first X characters, check if the folder exists, if not create it, use the next characters, check for subfolder, create if necessary, and finally copy the file to that folder and delete the original upon successful copy.

But honestly, I am still figuring this out too and while trying to answer your question was hoping it would answer mine, but it didn’t :(.

Good luck!

Hi,

this is a starting point


set baseDestinationDir to POSIX path of (path to desktop) & "destination/"

set sourceDir to (choose folder)
tell application "Finder" to set theFiles to files of sourceDir
repeat with aFile in theFiles
	set filename to name of aFile
	tell filename to set fullpath to baseDestinationDir & its text 1 thru 2 & "/" & its text 1 thru 3 & "/" & it
	do shell script "/usr/bin/ditto " & quoted form of POSIX path of (aFile as text) & space & quoted form of fullpath
end repeat