Apple Mail - Discard Spam
Summary: Completely deletes the messages in the Spam folder and the trash.
Requires: SpamSieve, Apple Mail
Install Location: ~/Library/Scripts/Applications/Mail
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.
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 Items" of menu "Mailbox" of menu bar item "Mailbox" of menu bar 1
try
click button "Erase" of window 1
on error
click button "Erase" 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 getStringDefaultLast Modified: 2011-03-07
Running the Script
You can use AppleScript Editor (AppleScript Utility prior to Mac OS X 10.6) to enable Mac OS X’s built-in Script menu. To run the script, just select it from the menu. FastScripts provides a similar menu that supports keyboard shortcuts and other features.