Sometimes my hard drive gets low on space, and various things don't work properly until I empty the Trash and free up some space. I know there are applications that empty the Trash after a set interval—but what I want is an app or script (or other means) to empty the Trash whenever there's e.g. less than 2GB of free space on a given hard drive.
I use a third party preference pane Compost that deletes from trash when the disk fills up or if the file has been in trash for a given time.
The original download stopped working for me but I have just found this on the author's site instead of the distributer. Note the author's comment
So it might not work even from this download
When I updated this I had just installed it on Yosemite and it installed (but not enough time to see if it deleted anything) I have now updated to El Capitan and the installer fails.
You could also edit the crontab with
Hazel supports keeping the trash under a certain size or keeping items only for a period like two weeks.
I use CleanMyMac, though there are lots of others that do a similar job. CleanMyMac also cleans cache, etc. Hazel is also good for cleaning out folders that fill up with rubbish quite frequently.
That's an interesting question.
I wrote a little shell script that will empty the trash if the available disk space falls before a threshold defined in the script (default is 10 GB but you can change that by editing the script).
Use launchd for automatic trash emptying
If you want this to run automatically, I recommend launchd. To do that
It will run every 5 minutes (300 seconds) by default. You can edit that too.
Notes and Disclaimer