Ok heres what I’ve got so far, This script basically is setting up proccessing area, where when a file is droped in a specific folder it stamps it with a specified prefix. This is working great so far. Now when the file gets dropped in the folder, it creates another folder with the date included in the folder name thanks T.J.
Now it gets a little complicated. For me anyway.
What I want next is for it to move the now prefixed file to the new folder that was created. It needs to check first to see if the new folder with the current date on it has allready been created and if so just move the prefixed file into it. If not or if the folder has yesterday’s date on it, it will then create the new folder with todays date on it and move the prefixed file into it. Compicated?? Heres the current script.
on adding folder items to thisFolder after receiving theAddedItems
tell application "Finder"
-- Activate to ensure that the displayed dialog will be visible
activate
-- Get the input from the user
set theDate to current date
set theDay to the day of theDate
set theMonth to the month of theDate
set thePrefix to "abc_"
-- Loop through the added items (only), adding the prefix to their names
repeat with thisItem in theAddedItems
set the name of thisItem to thePrefix & the name of thisItem
end repeat
end tell
tell application "Finder"
activate
make new folder at folder "existing folder name" with properties {name:" new folder " & theMonth & " " & theDay}
end tell
end adding folder items to
If this is asking too much, please email me for further discussion regarding bribery and much groveling…
JT
Ok, here’s a working model, but there are a couple of caveats:
- This guy’ll funk-out if the name of your original file is too long to accommodate the prefix.
- You’ll need to attach this script to your “in” folder. Whatever you want that to be, where you drop your files.
- It’ll create an “outbox” where your actual day/date filing happens. I ran into trouble creating folders within the folder action-attached folder because the folder action would ACT on those newly-created folders and the script would go haywire.
It’s not the most elegant way to go about your needs, but it works. And I’m sure others can lend tips and improvement suggestions on this script. Maybe even some that would eliminate the need for the outbox model.
on adding folder items to theFolder after receiving theAddedItems
repeat with thisItem in theAddedItems
tell application "Finder"
set theDate to current date
set theDay to the day of theDate
set theMonth to the month of theDate
set thePrefix to "abc_"
set itemName to name of thisItem
set newName to (thePrefix & itemName)
set name of thisItem to newName
if folder "Out-Box" of desktop exists then
set outBox to folder "Out-Box" of desktop
-- note this is the same junk as below. This would be better if it were in a subroutine or something, but it works.
if folder ("today_folder" & theMonth & theDay) of outBox exists then
move thisItem to folder ("today_folder" & theMonth & theDay) of outBox
else
make new folder at outBox with properties {name:"today_folder" & theMonth & theDay}
move thisItem to folder ("today_folder" & theMonth & theDay) of outBox
end if
-- end un-elegant approach
else
make new folder at desktop with properties {name:"Out-Box"}
set outBox to folder "Out-Box" of desktop
-- repeating un-elegant approach
if folder ("today_folder" & theMonth & theDay) of outBox exists then
move thisItem to folder ("today_folder" & theMonth & theDay) of outBox
else
make new folder at outBox with properties {name:"today_folder" & theMonth & theDay}
move thisItem to folder ("today_folder" & theMonth & theDay) of outBox
end if
-- end un-elegant approach
end if
end tell
end repeat
end adding folder items to
TJ, Testing it now, will let you know, Thanks again.
Ok I’ve changed around some of the folder names, and the script works, kind of. The problem arises when the date changes. I ran the script, no problem, prefix gets stamped on the file, the outbox gets created on the desktop and the folder with the date on it shows up with the prefixed file in it. All good so far. I then, changed the date in the control panels to the next day, to simulate what would happen tommorow. And the script errors with…
An error - 1728 occurred while the Folder Actions server was executing a script.
The second folder in the outbox gets created with the date in the name, but the file doesn’t move to that folder.
I know this is real close to working, not sure what the problem is.
Let me know what you think.
Thanks again, Please email me directly if you have any questions. JT
The problem might be that there is no check for the Outbox folder??? maybe? Still trying to figure it out.
jt
I think there was a space in the folder name. I renamed it thruout the script and a space got in one of em. With it taken out, it looks good, so far. I feel like such a apple geek. I am actually excited about this script working… Oh well go apple…
: )
Thanks a million.
JT
Hey TJ,
Got my script running well with the help of you and some others. As you said " 1) This guy’ll funk-out if the name of your original file is too long to accommodate the prefix. " It also funks out if if a file allready exists with the same name.
My thought would be to have a dialog box come up and tell the user, " hey this filename is too long please keep it below 31 characters and try agian and "hey this file allready exists please try again. In both cases the script should cease to run and remove the file from the folder that the user dropped it in.
Basically this script creates a file proccesing plant to attach prefixes to files as they are downloaded. And then moves them to a folder on the desktop. Neat huh? Let me know what you think and as always, thanks in advance. Here is the current working code. I’ve tried adding some if then lines to pop up the dialog, but have been unsuccesfull.
on adding folder items to theFolder after receiving theAddedItems
repeat with thisItem in theAddedItems
tell application "Finder"
set theDate to the current date --or any other date
copy theDate to b
set theyear to the year of theDate
set theDay to the day of theDate
set the month of b to January
set monthNum to (1 + (theDate - b + 1314864) div 2629728)
set thePrefix to "xyz_"
set itemName to name of thisItem
set newName to (thePrefix & itemName)
set name of thisItem to newName
set the comment of thisItem to thePrefix & itemName & return & monthNum & "/" & theDay & "/" & theyear
if folder "Comp Images" of desktop exists then
set compImages to folder "Comp Images" of desktop
--
if folder ("Comp Images " & monthNum & "/" & theDay & "/" & theyear) of compImages exists then
move thisItem to folder ("Comp Images " & monthNum & "/" & theDay & "/" & theyear) of compImages
else
make new folder at compImages with properties {name:"Comp Images " & monthNum & "/" & theDay & "/" & theyear}
move thisItem to folder ("Comp Images " & monthNum & "/" & theDay & "/" & theyear) of compImages
end if
--
else
make new folder at desktop with properties {name:"Comp Images"}
set compImages to folder "Comp Images" of desktop
--
if folder ("Comp Images " & monthNum & "/" & theDay & "/" & theyear) of compImages exists then
move thisItem to folder ("Comp Images " & monthNum & "/" & theDay & "/" & theyear) of compImages
else
make new folder at compImages with properties {name:"Comp Images " & monthNum & "/" & theDay & "/" & theyear}
move thisItem to folder ("Comp Images " & monthNum & "/" & theDay & "/" & theyear) of compImages
end if
--
end if
end tell
end repeat
end adding folder items to