How do I create a scheduled task that deletes files of a certain name everyday? Our voicemail system sends our messages to us via email as mp3 files. When I download the file, it comes down as "message.mp3", but of course OSX will rename them "Message (x).mp3" when you have more than 1. What I want to do is create a script/task that will automatically delete them everyday (or whatever I choose) as long as they're more than a couple days old.

I don't know how to a cron task, and one solution I came across was to create an AppleScript (which I also don't know well) and then use iCal to schedule an event everyday that runs the script. But it doesn't work.

Here's the AppleScript:

tell application "Finder"
    try
        delete (every file of folder "Macintosh HD:Users:username:Downloads" whose name starts with "message" and modification date is less than (get current date) - 2 * days)
    end try
end tell


And in iCal I created a repeating event, with the script attached.

Does anyone know how to do this (perhaps a better way?)
Add the following to your crontab (run env EDITOR=nano crontab -e to edit your crontab):

@daily /usr/bin/osascript -e 'tell application "Finder" to delete (every file of folder "Macintosh HD:Users:username:Downloads" whose name starts with "message" and modification date is less than (get current date) - 2 * days)'


Untested as I have no such files on my system. Keep backups and make sure you've got the right path.