I am currently trying to work out a script that will be for archiving, I am able to query a selected folder to return any subfolders that have not been modified in the last 90 days, but now I need to take each folder returned individually and perfrom certain tasks to it…any help will be appreciated
property retention : 90 * days
on run
open {choose folder}
end run
on open source_folder
set start_time to (current date)
set source_folder to item 1 of source_folder as alias
set cut_off to start_time - retention
tell application “Finder” to set the_folders to folders of source_folder
set folders_to_archive to {}
repeat with this_folder in the_folders
set this_folder to (this_folder as alias)
set the_info to (get info for this_folder)
if (modification date of the_info) < cut_off then set end of folders_to_archive to this_folder
end repeat
–do something with folders_to_archive
return folders_to_archive
end open
First, throw away your current script and replace it with:
on open sourceFolder
set 90daysago to (current date) - (90 * days)
tell application "Finder"
set oldFolders to every folder of entire contents of sourceFolder whose modification date is less than 90daysago
end tell
end open
Once you have this, ‘oldFolders’ will be a list of the folders in question, so just deal with them:
...
tell application "Finder"
set oldFolders to every folder of entire contents of sourceFolder whose modification date is less than 90daysago
-- maybe change their color?
set label index of oldFolders to 1
-- or maybe open them for perusal?
open oldFolders
-- or throw them away?
delete oldFolders
-- etc.
end tell
It may be that you need to do something individually with them (e.g. some action that can’t be applied to them all simultaneously) in which case you need to loop:
...
repeat with eachFolder in oldFolders
display dialog (name of eachFolder) & " was last modified on " & modification date of eachFolder as text
end repeat