I just wrote my first OSX script to automate copying images to an archive but I would like to take it further. Right now I choose the destination folder each time the script runs. I did this because the archive changes each month. The archive folders are 0001, 0002 etc… What I would really like to do is to check the date, check the last time the script ran and determine if it is a new month, if yes then create new archive folder one number above the last folder used. I know the command to check the date but I am lost at how to go about getting the comparisons. Any help would be appreciated.
Here is the script so far:
on adding folder items to this_folder after receiving added_items
set movedImages to choose folder with prompt "Select Archive Folder"
tell application "Finder"
try
duplicate added_items to folder movedImages
on error err
display dialog err
end try
end tell
display dialog ¬
"Image files have been copied to archives."
property oldDate : missing value
set currentDate to (current date)
(* note we take the date info once, in case you happen to be using the script close to midnight on the last day of the month…obscure bug prequashed! *)
if (oldDate is missing value) or (month of currentDate > month of oldDate) or (year of currentDate > year of oldDate) then
set oldDate to currentDate
--do stuff....
end if
I think I got that part…O_o? oh well… I also got years… if you just compare on months, when the new year hits January will not be greater than December ^_^…
UPDATE: OOPS, I see… you mean we don’t need to compare on greater than… just equal… I was thinking about a case where you don’t use the script for a year and end up in the same month… but I guess that case was already covered by checking the years… which I guess also don’t need to be checked for greater than… just equal. Until we get time travel anyway (or someone starts messing with your system clock)