I have a script that isn’t doing much, and I don’t know why. I want to delete chosen messages that are in the Trash folder.
property deleteFromNames : {"Zumies", "Dancing Wombats"}
tell application "Mail"
set counter to 0
set trashFolder to mailbox "Trash" of account "VP"
set trashMessages to messages of trashFolder
repeat with aMessage in trashMessages
set fromName to extract name from sender of aMessage
if deleteFromNames contains fromName then
set counter to counter + 1
delete aMessage
end if
end repeat
display dialog counter buttons {"OK"} default button 1
end tell
I’m getting a dialog with a result of 140, but they won’t delete. Not sure why. Can anybody provide some insight?
My accounts don’t have a “Trash” mailbox. they have a “Deleted Items” mailbox.
My iCloud account has a “Deleted Items” mailbox and a mailbox that views as “Trash”, but when viewed in AppleScript its real name is “trashFolder:Deleted Messages”
Run the script below and see if the list has a mailbox name in it called “Trash”
tell application "Mail"
set anAccount to account "VP"
return name of mailboxes of anAccount
end tell
If the name “Trash” is not in the list, then there is no way to get to that mailbox programmatically, even tho you can see it.
Protonmail IMAP. But I wouldn’t think the nature of the account should change the ability to delete emails in that folder, much like my Mail.app client allows me to.
Your script doesn’t work for me. But I see how you use the GUI to get to the deletion.
tell application "System Events"
tell application process "Mail"
click menu item "In All Accounts" of menu 1 of menu item "Erase Deleted Items" of menu 1 of menu bar item "Mailbox" of menu bar 1
end tell
end tell
works for me
Here is a version that will also click the button “Erase” in the sheet dialog that appears
tell application "System Events" to tell application process "Mail"
set mainWin to window 1 whose description is "standard window"
set mymenu to menu 1 of menu bar item "Mailbox" of menu bar 1
click menu item "In All Accounts" of menu 1 of menu item "Erase Deleted Items" of mymenu
repeat with i from 30 to 0 by -1
if exists sheet 1 of mainWin then exit repeat
delay 0.2
end repeat
if i > 0 then
click button "Erase" of (sheet 1 of mainWin whose description is "alert")
repeat with i from 30 to 0 by -1
if not (exists sheet 1 of mainWin) then exit repeat
delay 0.2
end repeat
else
return false
end if
end tell
I know this is old, but IIRC, as far as Mail.app is concerned, deleting a message equates to move to Trash folder.
Therefore, the script should work on non-Trash folders, but if the message is already in the Trash, there’s nothing for Mail to do (as far as it’s concerned)