I want to move junk messages older than x days to the Trash. I came across a script a while back that I was able to modify for my purposes. However, it moves the messages to the trash on the server of the account. While this is OK, an even better solution would be to move the messages to the Trash “On My Mac.” However, I can’t figure out how to reference the Trash on my local Mac. I am using 10.9, though the selection box only went up to 10.8. Any help would be appreciated. Thanks.
set DestinFolderName to "On My Mac - Trash" -- mailbox to move messages to. If you want to just delete them, leave it blank.
set StaleTime to 4 -- days old the message must be before moved or deleted
set ShowMailboxesProgress to false -- determines if you want the "Processing" box displayed for each mailbox
set CountMessages to 0
tell application "Mail"
set thisAccount to account "TEST"
set accountName to the name of thisAccount
set mailboxName to the name of mailbox "TestSpam" in thisAccount
if ShowMailboxesProgress then
display dialog "Processing folder " & mailboxName & " in account " & accountName
end if
try
set messages_list to every message of mailbox mailboxName in thisAccount
set NumItems to number of items in messages_list
-- display dialog "Number of items" & NumItems
repeat with i from 1 to number of items in messages_list
set theMessage to item i of messages_list
set difference to ((current date) - (date sent of theMessage)) div days
if difference is greater than StaleTime then
if DestinFolderName is not equal to "" then
move theMessage to mailbox DestinFolderName in thisAccount
set CountMessages to CountMessages + 1
else
delete theMessage
end if
end if
end repeat
end try
tell application "Growl"
set the allNotificationsList to {"Deleted Spam"}
set the enabledNotificationsList to {"Deleted Spam"}
register as application "Spam Delete" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "SpamSieve"
notify with name "Deleted Spam" title "Deleted Spam" description "I just moved " & CountMessages & " messages in the TestSpam folder older than " & StaleTime & " days to the Trash." application name "Spam Delete"
end tell
-- display dialog "Finished!"
end tell
quit
Model: MacBook Pro
AppleScript: 2.3
Browser: Safari 537.71
Operating System: Mac OS X (10.8)