Hi everyone.
well i am stuck.
i ahave searched the archive but can’t figure out how to combine what i have found with what i need.
i need a folder actioin that sorts files and then puts them into specific folders.
the problem i am having is that i can’t get my sript to drill down into any folder taht is placed in my “hotfolder”.
here is what i have so far:
on adding folder items to InPut after receiving theFiles
tell application "Finder" to repeat with indvFile in theFiles
set fileName to name of indvFile as text
try
if fileName contains "RHP" then
move indvFile to folder "Macintosh HD:Users:David:Desktop:RHP:" with replacing
else if fileName contains "LHP" then
move indvFile to folder "Macintosh HD:Users:David:Desktop:LHP:" with replacing
else
move indvFile to folder "Macintosh HD:Users:David:Desktop:Unknown:" with replacing
end if
end try
end repeat
end adding folder items to
any help you can give will be greatly appreciated!!!
thanks!!!
-david
Hi, David.
Assuming that your hot folder is empty before the drop and is meant to be empty again after the files are moved, this would do:
on adding folder items to InPut after receiving theFiles
tell application "Finder"
move (every file of entire contents of InPut whose name contains "RHP") to folder "RHP" of desktop with replacing
move (every file of entire contents of InPut whose name contains "LHP") to folder "LHP" of desktop with replacing
move every file of entire contents of InPut to folder "Unknown" of desktop with replacing
delete every folder of InPut
end tell
end adding folder items to
Dear Nigel,
SUPER GENIUS!
it works like a charm.
one last question, how would i delete the left over folders in the input folder?
thanks again!
-david
Could you be more specific? Nigel’s script moved every file left to “Unknown”, and then deleted all the folders remaining. Didn’t that part work? What did happen?
Hey Adam,
nigels script moved the files but left the folders in the input folder.
i was hoping that there would be ea way to delete the folder once it was emptied in the input folder.
thanks!
-david
So the last line: “delete every folder of InPut” doesn’t work? Can you enclose it in a try block and see what did happen:
tell application "Finder"
try
delete every folder of InPut as alias
on error e
display dialog e
end try
end tell
hey Adam,
If i just have this script as my folder action:
on adding folder items to InPut after receiving theFiles
tell application "Finder"
try
delete every folder of InPut as alias
on error e
display dialog e
end try
end tell
end adding folder items to
it deletes the folders in the InPut Folder.
if I use this one:
on adding folder items to InPut after receiving theFiles
tell application “Finder”
move (every file of entire contents of InPut whose name contains “RHP”) to folder “RHP” of desktop with replacing
move (every file of entire contents of InPut whose name contains “LHP”) to folder “LHP” of desktop with replacing
move every file of entire contents of InPut to folder “Unknown” of desktop with replacing
try
delete every folder of InPut as alias
on error e
display dialog e
end try
end tell
end adding folder items to
the empty folders remain in the InPut folder the same as nigels original script.
thanks for all the help!
david
You might need a delay, presuming that the move is not yet complete:
on adding folder items to InPut after receiving theFiles
tell application "Finder"
move (every file of entire contents of InPut whose name contains "RHP") to folder "RHP" of desktop with replacing
move (every file of entire contents of InPut whose name contains "LHP") to folder "LHP" of desktop with replacing
move every file of entire contents of InPut to folder "Unknown" of desktop with replacing
delay 2
delete every folder of InPut
end tell
end adding folder items to
Hey Adam-
nope they just sit there.
one caveat i haven’t mentioned the folders do not have any of the reference letters “rhp”, or “lhp”.
sorry if that was important.
thanks again for the help figuring this one out.
Hi, David.
Try leaving off the ‘as alias’. It tries to coerce the folder list to alias, not InPut. And InPut’s an alias anyway. But I’m mystified why you’re getting the problem with my original script. I can’t reproduce it.
Hi Nigel,
removing alia didn’t work either.
what i am using as a test case is a folder named test and then inside that folder another folder named test and then a file that is named test rhp.
the file move smotthly to the rhp folder so that part works.
its just that i am left with the 2 folders labled test in teh input folder.
so i need those folders deleted, becuase once this goes into production it will start eating away disk space if the folders remain, and more importantly my boss wants them deleted.
thanks for all of your help!
-david
Ah! Found it. I think. The problem isn’t apparently too many files, but too few! Reproducing your test exactly on my machine: when there are no files whose names don’t contain “RHP” or “LHP”, the line moving them to folder “Unknown” errors. This stops the script before it can delete the folders. I’ve no idea why this error occurs. The previous two lines don’t error when there’s nothing for them to move and I can’t see why the presence or absence of a filter in the reference should make any difference. Anyway, the cure on my machine is to put the offending line in a ‘try’ block.
on adding folder items to InPut after receiving theFiles
tell application "Finder"
move (every file of entire contents of InPut whose name contains "RHP") to folder "RHP" of desktop with replacing
move (every file of entire contents of InPut whose name contains "LHP") to folder "LHP" of desktop with replacing
try
move every file of entire contents of InPut to folder "Unknown" of desktop with replacing
end try
delete every folder of InPut
end tell
end adding folder items to
The error’s possibly due to some bug. Everything else works OK whether or not there are any files or folders on which to act…
Nigel,
I say again SUPER GENIUS!
it works flawlessly on my machine as well.
can’t thank you enough for all your hard work!
-david