Everyday we download a bunch of garbage from the net based on the projects we are working on that day. I need a better way to automate how all this is organized. I started by creating a folder action script that alters the modifacation date of todays downloaded files and changes them to today. (Im am not sure is it would be better to. alter the mod date or the creation date, but this seemed easier.) Now I need to figure out how to create another folder action script (or add on to the one i have) that creates folders based on the modification date starting with a folder for the year, sub-folders for the month and another for the day. Then I would like to have it move todays files to the folder it just created. Any idea on how to do all of this. Here is what I have so far.
on adding folder items to this_folder after receiving added_items
set nowDate to (current date) as date
-- CHANGE MOD DATE
repeat with i from 1 to number of items in added_items
set this_item to item i of added_items
tell application "Finder"
set the modification date of this_item to nowDate
end tell
end repeat
end adding folder items to
changing the creation date isn’t really possible, so changing the modification date is the better way,
it can be easily performed with the touch command of the shell.
This script creates the desired folders, changes the modification dates and move the files into the folder of the current day.
You have to adjust the path of the property in the first line
property destinationFolder : ((path to desktop as Unicode text) & "testFolder:")
on adding folder items to this_folder after receiving added_items
set todayFolder to createTodayFolder()
repeat with oneItem in added_items
do shell script "touch " & quoted form of POSIX path of oneItem
tell application "Finder" to move oneItem to todayFolder
end repeat
end adding folder items to
on createTodayFolder()
set {year:yr, month:mn, day:dy} to current date
set yrFolder to make_new_folder(destinationFolder, yr as text)
set mnFolder to make_new_folder(yrFolder, addZero(mn as integer as text))
return make_new_folder(mnFolder, addZero(dy as text))
end createTodayFolder
on make_new_folder(theFolder, fName)
try
return ((theFolder as Unicode text) & fName) as alias
on error
tell application "Finder" to return (make new folder at theFolder with properties {name:fName}) as alias
end try
end make_new_folder
on addZero(v)
return text -2 thru -1 of ("0" & v)
end addZero
Note:
set nowDate to (current date) as date
current date IS a date, so there is no coercion needed