Script to empty Mail's trash?

Hi,

I’m trying to script Mail but without much success. Does anyone have a script that will move all the messages from my Junk mailbox to the Trash mailbox and then delete them? The script below moves the messages from Junk to Trash without a fuss, but it won’t empty the trash. The script ends without error, but with the messages still in the trash folders. I have two subfolders in the trash folder: “On My Mac” and “Paul BunyaNet” (my ISP). Any ideas?

James.

tell application "Mail"
	activate
	beep
	move messages in junk mailbox to trash mailbox
	beep
	delete messages in trash mailbox
	beep
end tell

Model: 1.8 MHz G5 desktop single processor
AppleScript: 1.9.3
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

As already noted, the Code Exchange forum is for posting full snippets/solutions. In the future, please use the other forums for help requests. This post will be moved. (Also, please note the “Posting Etiquette” section of the posting guidelines.)

Try this.

tell application "Mail"
	activate
	beep
	move messages in junk mailbox to trash mailbox
	beep
	delete every message of trash mailbox
	beep
end tell

Thank you for replying, and sorry about the posting gaffe. I tried the snippet above, but it behaved the same way my original one had: messages were moved from Junk to Trash, but none of the Trash mailboxes–neither the main one nor the two sub-mailboxes inside it–were emptied. They simply accumulated the new messages. The routine finished without error, and all three beeps sounded. I notice that in my editor, the “to” before “trash mailbox” in line four isn’t in bold, whereas yours is. Could this be significant?

tell application "Mail"
	activate
	beep
	move messages in junk mailbox to trash mailbox
	beep
	delete every message of trash mailbox
	beep
end tell

Well, that one didn’t work either. This time, neither the messages in Junk nor the messages in Trash were touched at all. I tried changing “messages” to “every message” (see below) and lengthening the pause, but nothing happened there, either. It did run without error, though.


tell application "Mail" --version 2.0.5
	delete every message in junk mailbox
	delay 6
	delete every message in trash mailbox
end tell

Hey, it works here, too! Many thanks, Jacques.