Move files based on first 5 letters

Here is what I'm looking to do:
I have over 6000 folders with account documents in them, that I need to move to a different folder structure.
INPUT:
../99196-Kennedy/{Account Docs}
../FM026-Miller/{Account Docs}
OUPUT:
../99196_3078/{Account Docs}
../FM026_4440/{Account Docs}
The output folder structure is already built, as the 3078 in the output folder is a unique ID for a database we've built.
So I'm looking for a rule that will move the files based on the Account Number(99196) from the INPUT folders to the OUTPUT folders.
I know I can use the Matches criteria to get a custom value for the account number. The question I have is can I move that into another folder while having Hazel ignore everything after the account number in the new folder structure. I've tied using some apple script but it's not working well.
Apple Script:
I have over 6000 folders with account documents in them, that I need to move to a different folder structure.
INPUT:
../99196-Kennedy/{Account Docs}
../FM026-Miller/{Account Docs}
OUPUT:
../99196_3078/{Account Docs}
../FM026_4440/{Account Docs}
The output folder structure is already built, as the 3078 in the output folder is a unique ID for a database we've built.
So I'm looking for a rule that will move the files based on the Account Number(99196) from the INPUT folders to the OUTPUT folders.
I know I can use the Matches criteria to get a custom value for the account number. The question I have is can I move that into another folder while having Hazel ignore everything after the account number in the new folder structure. I've tied using some apple script but it's not working well.
Apple Script:
- Code: Select all
set inputFolder to choose folder with prompt "Choose input folder"
set outputFolder to choose folder with prompt "Choose output folder"
tell application "Finder"
set allFolders to folders of inputFolder
repeat with aFolder in allFolders
set baseName to text 1 thru 5 of (get name of aFolder)
set destinationFolder to (1st folder of outputFolder whose name starts with baseName)
move files of aFolder to destinationFolder
delete aFolder
end repeat
end tell