Hi, I’m a noob, so don’t eat me. A great guy named MAtt was helping we with this script, but I’ve really asked way too much of him, so I’m bringing this here. I’m trying to write a script that will sort my image files into folders, down through the hierarchy.
I’ve included a link to a photo, which I hope shows my intent.
This is what we have so far:
property firstfolderchars : ("0" as string) --This is added to the beginning of all folder names
on open itemsToSort
set scriptedFolder to choose folder with prompt "In which folder do you want your sorted folders?"
processitems(itemsToSort, scriptedFolder)
end open
on adding folder items to scriptedFolder after receiving itemsToSort
processitems(itemsToSort, scriptedFolder)
end adding folder items to
on run
set itemsToSort to choose file with prompt "Which files would you like to sort into sorted folders?" with multiple selections allowed
set scriptedFolder to choose folder with prompt "In which folder do you want your sorted folders?"
processitems(itemsToSort, scriptedFolder)
end run
on processitems(itemsToSort, scriptedFolder)
if (length of firstfolderchars) is greater than 220 then
set firstfolderchars to (characters 1 through 220) of firstfolderchars
end if
tell application "Finder"
set potentialproblem to ((scriptedFolder as string) & firstfolderchars & firstfolderchars) --check for file named equal to (firstfolderchars & firstfolderchars)
if ((file potentialproblem exists) and (kind of (info for file potentialproblem) is not "folder")) then
try
set name of file potentialproblem to (firstfolderchars & firstfolderchars & "qwertyasdfgzxcvb")
on error renameerror
display dialog renameerror buttons {"okay then"} default button 1
exit repeat
end try
end if
repeat with current_item in itemsToSort
set this_item to (info for current_item)
if (kind of this_item is not "folder" and this_item is visible) then
set targetfolder to (firstfolderchars & first character of (name of this_item))
if (exists folder targetfolder of scriptedFolder) is false then
try
make new folder at scriptedFolder with properties {name:targetfolder}
on error makefoldererror
display dialog renameerror buttons {"okay then"} default button 1
exit repeat
end try
end if
set filetodelete to ((scriptedFolder as string) & (targetfolder as string) & ":" & (name of this_item))
if (exists file filetodelete) is true then
try
delete filetodelete
on error
display dialog "Could not delete file \"" & (name of this_item) & "\" of " & (name of (info for targetfolder)) buttons {"okay then"} default button 1
exit repeat
end try
end if
try
move current_item to folder targetfolder of scriptedFolder
on error
display dialog "Could not move \"" & (name of this_item) & "\"" buttons {"okay then"} default button 1
exit repeat
end try
end if
end repeat
set filetochangenameback to ((scriptedFolder as string) & (targetfolder as string) & ":" & (firstfolderchars & firstfolderchars & "qwertyasdfgzxcvb"))
if (exists file filetochangenameback) then
try
set name of file filetochangenameback to (firstfolderchars & firstfolderchars)
on error renameerror2
display dialog renameerror2 buttons {"okay then"} default button 1
exit repeat
end try
end if
end tell
end processitems
Now, I don’t need the script to make new folders, just dump my image files into a folder, check that folcer to see if there is another folder that the image should go further down into, and then when it sees there is no more folders to go into, stop and move on to the next image. Sounds simple, but it’s been really hard to explain. I just want the files to be filed away automatically when I save them into that first folder. It works pretty great now, but it needs to be better if I’m going to put it to work.
It also has to be generic, so I can use it on any file thats’ name starts with numbers.
Gads, I’m getting more confused the more I talk…
Help! Please! Thank you!