Erik A. Hanson's Weblog

An AppleScript to Clean Up My Downloads Folder

Posted: August 11th, 2007    Tags: AppleScript, Mac OS X

My downloads folder always gets so full after a while that I have a hard time finding things. I like to keep stuff around for a little while in case I need it again, and if I have the space, I like to keep things around for a long time, just in case.

So I wrote a simple AppleScript to move old files to an “Old” subdirectory. I thought I’d post it here in case anyone else needed something similar. It’s a simple script, but AppleScript is hard for me because I write scripts so rarely that I forget everything about it before I need to write another script.

(Many years ago, I actually got paid to write a few AppleScripts.)

set folderName to "Macintosh HD:Users:your-user-name:Temp:"

repeat with fileName in list folder folderName
  set tempFile to (folderName as string) & contents of fileName
  set modificationDate to modification date of (info for alias tempFile)
  set age to ((current date) - modificationDate) / days

  if age > 7 and fileName is not " Clean Up Temp Dir" then
    tell application "Finder"
      move alias tempFile to alias (folderName & " Old")
    end tell
  end if
end repeat


Leave a Reply



(Comments are moderated to keep out spam. Please be patient.)