AppleScript: Delete old folders
If you work like I do, then you have a hierarchy of folders contained in a single folder that allows you to manage project files, notes, etc. Well, when it comes time to chunk those old files, normally you have to manually go through and remove them; this task can become daunting if you have multiple project folders. I am going to show you an easier way. In this how-to, we'll cover how to create an AppleScript that will allow you to remove folders that are older than 30 days. Continue reading to learn how to create this AppleScript.
Creating the AppleScript
Open Script Editor.app (it can be found in /Applications/AppleScript). When you have the application opened, type (or copy / paste) the entire AppleScript below.
set backupFolder to (choose folder)
tell application "Finder" to set theseFolders to (get folders of backupFolder)
repeat with oneFolder in theseFolders
if (creation date of (info for oneFolder as alias) < (current date) - 30 * days) then
tell application "Finder" to delete oneFolder
end if
end repeat
When you are finished, your script should look similar to the one below.

You can save this script as an application by clicking File > Save As, and choosing "Application" from the "File Format" drop-down box. Type a name and location for your script to be saved and then click the "Save" button.

To run this script, you can double-click on the application that you just created or you can drag it into the dock for easy clicking. When you run the script, you will be presented with a dialog asking you for a folder. Browse to the parent (top-level) folder that contains folders you would like to be searched by date. The script will then find the folders that are older than 30 days and move them to the Mac OS X trash bin.
Additional notes
- Before you remove the files from the trash bin, make sure they are the files you wanted to delete.
- This script only removes folders, so be sure to organize your files within the folders accordingly.
- Be cautious when using this script, as it moves files. TUAW is not responsible for data loss due to incorrect usage of this script.
Share
Source: http://tuaw.com/tag/AppleScript
If you work like I do, then you have a hierarchy of folders contained in a single folder that allows you to manage project files, notes,...
Add a Comment
Why not just highlight them all and hit command-delete?
May 06 2008 at 12:25 PM Report abuse Permalink rate up rate down ReplyAnd how would the script look for empty folders?
May 05 2008 at 3:37 PM Report abuse Permalink rate up rate down ReplyPicazsoo - I'll be the first to admit I often forget how many posters don't speak English as their first language. And I'm duly impressed that they can master technology in anything other than their native language.
But the "just" thing pervades every single posting about how to do something. And people who DO speak English as their first language use the phrasing over and over again. I don't know if they realize it's offensive or not. But it is. Simply adding the word "just" devalues the content of the post, if people realize it or not.
I apologize for offending you. I don't know why I ever mention the JUST thing, it's one of those things I need to learn to ignore if I'm going to participate in sites like this.
I'll definitely try to avoid this evil "just" from now on (-:
About the tech stuff: Almost all technology I use is in english language. I went to Texas last year as an exchange student, but there are some things one will never learn unless one's a real native speaker.
I'm glad we figured this out.
End of Transmission
Some day I'd like to see a how-to post somewhere, anywhere, without any comments that say, "Wouldn't it be easier to just..."
Go ahead, suggest ANOTHER way. The more ways the better. But to suggest your way is the best way and every other way is inferior is arrogant. Take a look around. Just, just just just just just. "Why not just....?" "Couldn't you just.....?" So annoying.
Look - JUST write your other method without slamming the way someone JUST took the time to write up. Leave the JUST out.
Well said Murphy. Well said.
May 05 2008 at 2:33 PM Report abuse Permalink rate up rate down ReplyI am sorry if my comment did sound like that. I am not from an english speaking country so these nuances in language aren't as easy to understand as you might think.
On the other side, I didn't want to be offensive in any way, but you surely wanted to. Actually the reason I posted what I posted was because I hoped someone would suggest the way to do what I wanted. I use Hazel to do this kind of stuff.
Sincerely, Jachym Metlicka
find /path/to/directory -type d -mtime +30 -exec rm -r {} ;
May 05 2008 at 12:31 PM Report abuse Permalink rate up rate down ReplyThanks. That's much easier (-:
May 05 2008 at 2:34 PM Report abuse Permalink rate up rate down ReplyWouldn`t it be safer to just label those folders with a certain colour and later search in Finder for all folders with this label and delete them from there? It is much safer than just moving them straight to trash...
Just my 2 cents...
Hot Apps on TUAW
Deals of the Day
more deals- Altec Lansing Octiv Duo iDock for $48 + free shipping
- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



10 Comments