just like to add in my script based on the above
i've been looking for something similar to this for a while and tried allsorts of snipets from many of the posts so heres my attempt
this actually uses the mailbox or folder that is selected in mail.app so you dont have to explicitly tell it which folder you want to use (had that part of the code from another post somewhere so credit to them not me
🙂
display alert "Please note!" message "This script may take a while if you have a lot of mailboxes selected. Do you want to continue?" buttons {"Cancel", "Yes"} cancel button "Cancel"
tell application "Mail"
tell front message viewer
set theSelectedMailboxes to selected mailboxes
repeat with a from 1 to length of theSelectedMailboxes
set theCurrentMailbox to itema of theSelectedMailboxes
processMailbox(theCurrentMailbox) of me
end repeat
end tell
end tell
on processMailbox(theMailbox)
tell application "Mail"
set unread_messages to (messages of theMailbox whose read status is false)
set unread_count to countunread_messages
--display dialog "Total unread messages: " & unread_count
repeat with each_message in unread_messages
set the_subject to subject of each_message
set the_sender to sender of each_message
set the_action to choose from list {"Open", "Mark as read", "Keep for later", "Delete"} default items {} with prompt "Subject: " & the_subject & return & return & "Sender: " & the_sender & return & return & "What do you want to do with this message?" & return with title "Unread message" without multiple selections allowed
if the_action is false then return
if item 1 of the_action is "Open" then open each_message
if item 1 of the_action is "Mark as read" then set read status of each_message to true
if item 1 of the_action is "Delete" then
set read status of each_message to true
set junk mail status of each_message to true
end if
end repeat
end tell
tell application "AppleScript Editor"
activate
display dialog "Do you want to delete the email?" buttons {"yes", "no"} default button 2
if result = {button returned:"yes"} then
tell application "Mail"
# deletes every message that is Read and marked as Junk.
# Any that are not read AND junk will remain.
delete (every message of theMailbox whose junk mail status is true and read status is true)
end tell
else
if result = {button returned:"no"} then
end if
end if
end tell
end processMailbox