Wednesday, April 01, 2009

Erase Junk Mail

One of the little bug-bears with some of the Apple applications are the little things that are missing. Take the fact that Mail doesn't have the ability to set a flag to delete the contents of the junk mail folder when you close Mail. Or better still, why not have a setting to delete the junk mail at the end of the day?

This got me thinking and after a little digging around I decided that it couldn't be that complicated to create an AppleScript to do the job. Someone must have done it already, but I couldn't find it so I had a go a writing one myself!

Here's the simple script that I've written:


tell application "Mail"
set junkMessages to every message of junk mailbox
repeat with junkMessage in junkMessages
set deleted status of junkMessage to true
end repeat
end tell

It seems to work. I've tested it a couple of times and enjoyed watching my junk mailbox empty before my very eyes.

Of course you might be thinking, why doesn't he just use the keyboard shortcut to do the job? Well I wanted to try something else. Having read about how you can launch scripts from iCal events, I thought that it might be rather neat to write the delete script and then schedule it in iCal at the end of each day.

If you open iCal and create an event "Delete Junk Mail" you can set the alarm to run the script. You can of course create this event as a recurring event in a hidden calendar so that it doesn't show up in your current view of iCal but works away in the background. 

I might try this for syncing my phone rather than the Proximity app running a script as I do now. As it is, I'm going to have to wait until tomorrow morning to see if my 10:00pm event to delete my junk mail works.

I'll let you know.

No comments: