Hawaiian Scuba Dude

Q: Automatically removing trash 5 days old

Hi

I did a secure empty trash yesterday which I have not done in a few years and there were over 1.5  million files to permanently erase.   This is dangerous to keep this much trash and it takes way too long to clean up.  I would prefer regular maintenance . . . to securly and automatically empty the trash regularly and still maintain the benefit being able to prevent accidental deletion of recent work.  The requirement therefore would be to perhaps during off hours, once a day or upon startup automtically secure empty trash only items that have aged in the trash at least x days.

 

Can this be done quickly and simply with applescript or a cron job?

Posted on Jul 12, 2011 12:58 AM

Close

Q: Automatically removing trash 5 days old

  • All replies
  • Helpful answers

first Previous Page 3 of 3
  • by Tony T1,

    Tony T1 Tony T1 Jul 19, 2013 4:20 AM in response to twtwtw
    Level 6 (9,249 points)
    Mac OS X
    Jul 19, 2013 4:20 AM in response to twtwtw

    I had a thought.  How about adding a Folder Action to the Trash to touch files trashed?

    I tried this, but couldn't even get a simple folder action to work even on a new folder (I used Automator to run a shell script "touch" for files added to a folder, but it didn't work)

  • by Tony T1,

    Tony T1 Tony T1 Jul 20, 2013 5:12 AM in response to Tony T1
    Level 6 (9,249 points)
    Mac OS X
    Jul 20, 2013 5:12 AM in response to Tony T1

    OK, found a solution to fixing this.  To change the file modification date to the date added to the Trash:

     

    From: http://apple.stackexchange.com/questions/7947/sort-trash-files-by-date-trashed

     

    Go to the AppleScript Editor, past in the following script and save it in /Library/Scripts/Folder Action Scripts

    on adding folder items to this_folder after receiving added_items

      repeat with this_item in added_items

      do shell script "touch -m " & quoted form of POSIX path of this_item

      end repeat

    end adding folder items to


     

    Then right click on any folder in Finder, go to Services and click Folder Actions Setup go to /Library/Scripts/Folder Actions and select Configure Folder Actions.  Cancel the dialog asking which script to attach. Click the checkbox to Enable Folder Actions, then click the plus sign to choose the recycle bin folder. Click CMD+SHIFT+G ( ( or hold CMD+SHIFT+. ) and type in ~/.Trash, click ok and then click open. Now on the right side click the plus sign to choose the AppleScript that you saved earlier.

    Note: I changed do shell script "find " & quoted form of POSIX path of this_item & " -exec touch {} \\; to do shell script "touch -m " & quoted form of POSIX path of this_item

  • by Tony T1,

    Tony T1 Tony T1 Jul 20, 2013 7:24 AM in response to Hawaiian Scuba Dude
    Level 6 (9,249 points)
    Mac OS X
    Jul 20, 2013 7:24 AM in response to Hawaiian Scuba Dude

    use the srm terminal command for secure rm

  • by Tony T1,

    Tony T1 Tony T1 Jul 22, 2013 2:07 PM in response to Tony T1
    Level 6 (9,249 points)
    Mac OS X
    Jul 22, 2013 2:07 PM in response to Tony T1

    Just realized that if a folder with files is trashed, then only the Folder will be touched.

    So, the original script I linked was correct.

    The correct script, that will touch recursively is:

     

     

    on adding folder items to this_folder after receiving added_items

              repeat with this_item in added_items

                        do shell script "find " & quoted form of POSIX path of this_item & " -exec touch {} \\;"

              end repeat

    end adding folder items to


  • by Monsignor Paolo,

    Monsignor Paolo Monsignor Paolo Sep 23, 2013 9:00 PM in response to Tony T1
    Level 1 (10 points)
    Mac OS X
    Sep 23, 2013 9:00 PM in response to Tony T1

    It seems, it's not a good idea to set the date deleted using Folder Actions.

    The Folder Actions technology is not suitable for heavy payload.

    If you'll try to delete many files, hunders at the time, this script will executed many and many times and will miss some files.

    I tried to delete about 4000 small files, many files remained in Trash with old date, and I got unclosing "Deleting to Trash" small Finder window, so I was forced to relaunch Finder. Later in Console I found multiple records with "Folder Actions respawn in...sec".

    Please, be careful.

  • by Tony T1,

    Tony T1 Tony T1 Sep 24, 2013 5:25 AM in response to Monsignor Paolo
    Level 6 (9,249 points)
    Mac OS X
    Sep 24, 2013 5:25 AM in response to Monsignor Paolo

    I wonder if the folder action would have worked better if the 4000 or so files were first put into a folder/directory and then trashed.  Would the Folder Action then have only 1 file to process?

  • by Monsignor Paolo,

    Monsignor Paolo Monsignor Paolo Jul 9, 2014 5:38 PM in response to Hawaiian Scuba Dude
    Level 1 (10 points)
    Mac OS X
    Jul 9, 2014 5:38 PM in response to Hawaiian Scuba Dude

    After many days at Google (DuckDuckGo) I found an app that can solve this problem forever.

    It's name is TrashTimer. You can download it here.

    Works well, there is small trouble, when program starts, it shows the attention window, I can't avoid it, but everything else is OK.

    Please test it and give your opinion.

  • by ertpoy,

    ertpoy ertpoy Aug 19, 2015 11:58 PM in response to Monsignor Paolo
    Level 1 (0 points)
    Aug 19, 2015 11:58 PM in response to Monsignor Paolo

    TrashTimer

    Tested and Approved!

first Previous Page 3 of 3