I am trying to do an automator calendar event where every Friday, it deletes files whose date modified is older than 30 days; EXCEPT files within folders labeled red.
I have my Documents folder with 3 files, one folder created today and labeled red, a folder last modified a week ago, and a pdf that was modified more than 30 days ago.
My automator script goes as follows:
[Find Finder Items] Search "Documents", ALL of the following are true:
-Date last modified is not in the last 30 days
-Label is not red
[Move Finder Items To Trash]
//end
But this moves the red labeled folder and the older pdf, when it should only move the pdf to the trash.
Can anyone help me? Thank you!
Edit: Running macOS 10.13.3
Best Answer
My initial suggestion to the problem was to replace the actions you currently have in your Automator workflow with a Run AppleScript action that uses this command:
You would then have either added an action after this to trash those items, or change
get every item
todelete every item
in the script. However, as @user3439894 pointed out, this won't traverse folder trees, so any items inside a folder that are older than 30 days (and not tagged red) will escape detection.The following script is an example of a method that uses recursion to descend through the directory tree deleting files (or marking them for deletion) as it goes:
I have tested it briefly on my own fairly complex tree structure, and it appeared to work successfully. However, I'm writing this and testing it whilst quite tired, but regardless, I would always strongly advise that you test this script yourself on dummy files and folders to ensure it works. Please report back on how it goes, including—if they arise—any errors, with specific details on how I can reproduce the error myself.