Choosing ALL vs. manually selecting mailboxes in Mail?

I am successfully using the script below to mark all messages read in a faster manner than checking the status of every individual message. I cannot figure out the syntax to select ALL mailboxes vs. having to manually select mailboxes. When I changed ‘selected mailboxes’ to ‘every mailbox’, I get an error: “Can’t get every mailbox of message viewer 1.”

Does anyone have an idea on how to have this script look at every mailbox instead of having to manually select them?

Thanks!


set processSubMailboxes to true
tell application "Mail"
	tell front message viewer
		set theSelectedMailboxes to selected mailboxes
		repeat with a from 1 to length of theSelectedMailboxes
			set theCurrentMailbox to item a of theSelectedMailboxes
			processMailbox(theCurrentMailbox, processSubMailboxes) of me
		end repeat
	end tell
end tell

on processMailbox(theMailbox, processSubMailboxes)
	tell application "Mail"
		if processSubMailboxes = true then
			set theSubMailboxes to every mailbox of theMailbox
			repeat with a from 1 to length of theSubMailboxes
				set theCurrentSubMailbox to item a of theSubMailboxes
				processMailbox(theCurrentSubMailbox, processSubMailboxes) of me
			end repeat
		end if
		tell application "Mail" to activate
		tell application "Keyboard Maestro Engine"
			do script "Mark All Mail Read"
		end tell
		
		set theSelection to selection
		set theMessage to item 1 of theSelection
				
		if read status of theMessage is false then
			tell application "Mail" to activate
			tell application "Keyboard Maestro Engine"
				do script "Mark All Mail Read"
			end tell
		end if
		
	end tell
end processMailbox


Hi. If I understand the question, I think one or more of these lines would apply.


tell application "Mail" to set (inbox's messages whose read status = 0)'s read status to 1

tell application "Mail" to set (trash mailbox's messages whose read status = 0)'s read status to 1

tell application "Mail" to set (junk mailbox's messages whose read status = 0)'s read status to 1

Thanks, Marc. I have 20+ mailboxes so I am trying to programmatically select all of them. I can do it by looping ‘selected mailboxes’ (after manually selecting them with the mouse) but I am trying to find the syntax for choosing all mailboxes in AppleScript. Does that make sense?

Thank you.