Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A set of scripts to erase deleted files based on age System
I have always wanted to have the ability to remove files from the trash which were deleted a long time ago. I have just written an AppleScript which renames files and/or folders after they have been put into the Trash to help with this task. Date and time are added to the original filename. So for example, if the file XYZ.txt has been deleted, then the script renames it to _@_YYYYMMDD-HHMMSS_XYZ.txt. This gives me the possibility to sort those files and folder by date and time.

I had to put an identification string (_@_) at the beginning because the Repeat loop takes the newly renamed files into account, which produces a never-ending loop. Maybe somebody can find a better solution.

I used Folder Actions (implemented on OS X 10.3 and newer) on the Trash folder (~/.Trash) to let this script run as soon as a file or folder has been put inside. Copy/paste the script into the Script Editor and save it as and Application under the name ToTrash into ~/Library -> Scripts -> Folder Action Scripts to use it in this manner.

To accompany this script, I have written another that then checks the renamed files and deletes those older than a specified age. The number of days (which is presently set to 15) can be changed in the perl part of the script (localtime(time - 15 * 86400);). The path Macintosh HD:Users:user:.Trash: must be customized to match your machine.

[robg adds: I haven't tested these scripts.]
    •    
  • Currently 1.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[13,175 views]  

A set of scripts to erase deleted files based on age | 10 comments | Create New Account
Click here to return to the 'A set of scripts to erase deleted files based on age' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A set of scripts to erase deleted files based on age
Authored by: Toadling on Mar 29, '07 08:42:08AM
I like AppleScript, and I'm all for adding custom functionality to your system, but I took the easy way out and just bought a license for the Hazel preference pane ([link:]http://www.noodlesoft.com/hazel.html). Although some of its functionality can be replicated with Folder Actions, Hazel has a really elegant user interface for doing these kinds of things.

[ Reply to This | # ]
Why rename?
Authored by: SeanAhern on Mar 29, '07 11:48:06AM

While I like this in concept, I do have to ask why you're renaming the files? With a renamed file, you can't just move a file out of the Trash and put it where you want. You also have to manually strip off the appended date/time stamp.

Instead, why not create subdirectories into which files are placed? That doesn't really place much burden on the file system, but still gives you a nice organizational system. Heck, with an appropriate amount of scripting, you might even be able to make a useful set of folders like "Yesterday", "Last Week", "One Month Ago", etc. that your files are moved among.



[ Reply to This | # ]
Why rename?
Authored by: plagarri on Mar 29, '07 01:53:26PM

Because there is a better overview of the files in case you are looking for a deleted file, I think it is simply easier to search in one level.
But you can easily modify the scripts to adapt it to your need or preference.
Concerning Hazel from Noodlesoft, the trash functionality is not comparable to what I made.



[ Reply to This | # ]
A set of scripts to erase deleted files based on age
Authored by: AJB on Mar 29, '07 03:03:14PM

Better still, instead of renaming, or creating folders, 10.4 supports custom extensible metadata. Just create a DateMovedToTrash metadata field.



[ Reply to This | # ]
A set of scripts to erase deleted files based on age
Authored by: plagarri on Mar 30, '07 12:26:12AM

Can you explain how to create and use those custom extensible metadata fields: DateMovedToTrash ?



[ Reply to This | # ]
A set of scripts to erase deleted files based on age
Authored by: DavidRavenMoon on Mar 30, '07 08:02:41AM

Why would you keep all that stuff in your trash? I throw stuff in there and then empty it. That;s why I trashed it. Why waste hard drive space? If I want to archive it it goes on CD or DVD.

---
G4/Digital Audio/1GHz, 1 GB, Mac OS X 10.4.9 • www.david-schwab.com • www.myspace/davidschwab • www.imanicoppola.net



[ Reply to This | # ]
A set of scripts to erase deleted files based on age
Authored by: fxt on Mar 30, '07 10:59:22AM

the simple one-line command

find . -atime 15 -delete

deletes all files in the current directory older than 15 days.
tiny variations around this basic command (man find)
should do what you want. no mess, no fuss.



[ Reply to This | # ]
A set of scripts to erase deleted files based on age
Authored by: plagarri on Mar 30, '07 11:01:18PM

Find -atime is the "last access time", but what I made and what OS X doesn't keep is the "delete time", the moment where the file has been put into the trash.



[ Reply to This | # ]
A set of scripts to erase deleted files based on age
Authored by: Oceanhints1 on Mar 31, '07 01:36:41AM

I second DaveRaveMoon, why keep anything inTrash?? A total waste of disk space!

It is there for the simple reason to contain files you no longer wish to keep.

As soon as files are put in it, press Shift-Command-Delete

Files gone! No messing around.



[ Reply to This | # ]
A set of scripts to erase deleted files based on age
Authored by: DavidRavenMoon on Mar 31, '07 01:11:54PM

I get people coming to me for help all the time that say "I'm getting a notice that I'm running out of hard drive space? What should I do" and I look and they have a year's worth of files in the trash! Like 10,000 items! I tell them "empty the damn trash already!" They always look surprised... "really?"

Then there's the people who throw files in the trash on a Zip disk, but don't empty it, and wonder why they have no room!

Most of these people were former Windoze users... ;)

---
G4/Digital Audio/1GHz, 1 GB, Mac OS X 10.4.9 • www.david-schwab.com • www.myspace/davidschwab • www.imanicoppola.net



[ Reply to This | # ]