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

About Me

I'm a software developer and consultant in San Francisco. I mostly develop web apps in Javascript, Java and Rails. There's a little more about me on my LinkedIn profile.

Recent Projects

wshlst.com: a group-oriented wish list website.

BoardsConsult​/​RotationTracker: a site to help medical residents prepare for the U.S. Medical Licensing Exam, and a related site to help medical schools evaluate and track the progress of the residents in their programs.

Jobs

I moderate a few completely free jobs mailing lists with RSS feeds and zero spam: XP jobs, Rails jobs and Mac development jobs. Also, my pals at Pivotal Labs have agile Rails and Java job openings.

Plug: Web Hosting

Looking for cheap shared web hosting and/or domain registration? I've been using DreamHost for years and I've been very happy with them. They offer tons of disk space and bandwidth, one-click installation for apps like WordPress and Gallery, unlimited domains, thousands of email accounts, private domain registration, and more. They are also a nice bunch of folks, not some big dumb company.