Apple Mail - Discard Spam
Summary: Completely deletes the messages in the Spam folder and the trash.
Requires: SpamSieve, Apple Mail
Install Location: ~/Library/Scripts/Mail Scripts/ on Panther or ~/Library/Scripts/Applications/Mail on Tiger
Description
Running this script from the Scripts menu will completely delete all the messages in the Spam folder (rather than putting them in the trash). It will also delete any messages that are in the trash.
Note that this script does not work when run from Mail’s Scripts menu. You need to run it from the system Scripts menu, next to the clock on the right side of the menu bar. (This is the only Script menu available on Mac OS X 10.4.)
Download in Compiled Format | Download in Text Format
Script
global spamFolderName
set spamFolderName to getStringDefault("AppleMailTrainSpamName", "Spam")
tell application "Mail"
delete every message of mailbox spamFolderName
end tell
tell application "Mail" to activate
tell application "System Events"
if (system attribute "sysv") < 4144 or UI elements enabled then
tell application process "Mail"
click menu item "In All Accounts" of menu 1 of menu item "Erase Deleted Messages" of menu "Mailbox" of menu bar item "Mailbox" of menu bar 1
try
click button "OK" of window 1
on error
click button "OK" of sheet 1 of window 1
end try
end tell
else
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
beep
display dialog "GUI Scripting is not enabled." & return & return & "Check \"Enable access for assistive devices\" in the Universal Access preference pane (authentication is required), then run this script again." with icon stop buttons {"OK"} default button "OK"
end tell
end if
end tell
on getStringDefault(theKey, defaultValue)
tell application "SpamSieve"
set theKeys to {theKey}
set theDefaults to {defaultValue}
try
set {theResult} to lookup keys theKeys default values theDefaults
on error
set {theResult} to theDefaults
end try
return theResult
end tell
end getStringDefault