Latest in Applescript

Image credit:

AppleScript: Delete old folders

Cory Bohon

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 (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.

Saving the script
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.

Running the script
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.

From around the web

ear iconeye icontext filevr