1

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?)

  • If you don't know cron or shell scripting this is probably the best way as you understand what it is doing and can change/fix it as needed. If you know shell etc then there are other ways – mmmmmm Jul 21 '14 at 21:37
1

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.

| improve this answer | |
  • Thanks, didn't know about that. I'll give it a shot. – Justin_T Jul 21 '14 at 20:07
  • Doesn't this assume that you area logged in - surely better to use a shell script here. Also OSX preferred way is launched not cron (as the OP does not know either might be better to start on that especially with a GUI) – mmmmmm Jul 21 '14 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .