-- Downloaded From: http://c-command.com/scripts/spamsieve/apple-mail-discard-spam -- Last Modified: 2011-03-07 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 getStringDefault