Applescript - AppleEvent handler failed on set properties {visible messages: }
From comments…

As it would appear that many people across the net are struggling &amp; failing to get set properties to {visible messages:msgList} to work at all, it might be simpler in the long run to just pop up a count of unread/unflagged messages &amp; optionally sort by flagged then unread for easy discovery in the Mail window.

I added in a 'sort by date or flags/unread' option in the dialog, too

tell application "Mail"
    tell the front message viewer
        set unReadMsgs to every message whose read status is false and flagged status is false
        display dialog ("There are " &amp; (count of unReadMsgs) as string) &amp; ¬
            " Unread/Unflagged messages." buttons {"Sort Unread", "Sort Date"} ¬
            default button "Sort Date" giving up after 300
        set theResult to button returned of result as string
        if theResult is "Sort Date" then
            set properties to {sort column:date received column}
        else if theResult is "Sort Unread" then
            set properties to {sort column:flags column}
            set properties to {sort column:message status column}
        end if
    end tell
end tell