Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Susja

macrumors regular
Original poster
Feb 22, 2017
199
7
Hello.
I want to delete all files from my MacBook Pro 2015 running 10.14.2 that were downloaded recently.
I simply want to keep this folder empty and keep files only for 2 days.
Something is wrong with my 'conditional' operator. Likely it's my fault but I can't figurer it out.
If I setup 'Filter Finder Items' for 'created' or 'modified' today and create a new file it works fine.
But I want to keep it for 2 days hence I set it up as 'Date last modified' is 'in the last 2 days' and create a copy/paste a file in Download folder a week old and then modify it ... it does not work 'as expected' i.o. it does not move it to Trash.
Hence: here my question: what operator should I use and which condition to set in order to move files from Download folder that are 'older' than 2 days?
Thanks
 

Attachments

  • Screen Shot 2018-12-27 at 5.39.31 PM.png
    Screen Shot 2018-12-27 at 5.39.31 PM.png
    128.8 KB · Views: 609

Brammy

macrumors 68000
Sep 17, 2008
1,718
690
I would suggest using Hazel by Noodlesoft. It excels at these kinds of automated file management tasks.
 

Susja

macrumors regular
Original poster
Feb 22, 2017
199
7
Well I did not know about this utility ...
Anyway I prefer to use ‘native’ app like Automator because it’s part of iOS and free as well
Thanks anyway
 

Brammy

macrumors 68000
Sep 17, 2008
1,718
690
I am not sure if Automator can constantly scan the Folder, but it might be possible to trigger it on a calendar event. Like, every day at midnight.

Hazelsoft is relatively cheap and can constantly scan the folders, which is helpful.

That said, I think your logic is a little off. You want it to be "NOT within the last 2 days" or you will be deleting stuff in the last two days.
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
You could maybe try the "Run Shell Script" action with something like this:

Code:
find ~/Downloads -maxdepth 1 -type d -mtime +2d -exec [U]echo[/U] rm -rf "{}" \;

I strongly suggest you read the man page for the find command. The above command currently set to find all folders over 2 days old in the top level of your Downloads folder. The man page will tell you how to tweak it.

Try it from the Terminal first - note that the example above just lists the delete commands its going to run. Delete the "echo" to make it actually delete them once you're happy its not going to do Something Bad.

***Remember to proceed with caution when automating the deletion of files/folders!***
 
  • Like
Reactions: Susja

Susja

macrumors regular
Original poster
Feb 22, 2017
199
7
You could maybe try the "Run Shell Script" action with something like this:

Code:
find ~/Downloads -maxdepth 1 -type d -mtime +2d -exec [U]echo[/U] rm -rf "{}" \;

I strongly suggest you read the man page for the find command. The above command currently set to find all folders over 2 days old in the top level of your Downloads folder. The man page will tell you how to tweak it.

Try it from the Terminal first - note that the example above just lists the delete commands its going to run. Delete the "echo" to make it actually delete them once you're happy its not going to do Something Bad.

***Remember to proceed with caution when automating the deletion of files/folders!***
Hi superscape,
I like your suggestion. It really worked for me when I replaced -type d for -type f
Anyway ... I could write the script to execute something similar but it'll require to setup scheduler or add this script somewhere to launched at some point or etc.
My point was (just for fun) to use Automator i.e. use graphical interface instead of command line.
Anyway I appreciate your help
 

Susja

macrumors regular
Original poster
Feb 22, 2017
199
7
Hi there,

You can certainly mix and match Automator and shell scripts. I wrote a quick "How To" a while back. Take a look here of you like:

https://www.ghostotter.com/making-shell-scripts-little-user-friendly/

-superscape,
your link to the document is great. I checked it and tried. It worked for me perfectly. Thanks for that.
The only issue that left ( I did not find it in your page ) ... that in your case user could 'search' explicitly for some file But in my case the goal was to use Automator run automatically.
In other words when I put my script in Automator and run it ... it moves 'old' files from Downloads folder to Trash but how could I setup Automator to run it itself?
Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.