1

I have the following applescript working under Lion, but it returns this Error: -10000. Mail got an error: AppleEvent handler failed. error under Yosemite.

try
tell application "Mail"
    set theViewer to front message viewer
    set theMsg to messages of theViewer
    set msgList to {}
    repeat with thisMsg in theMsg
        if read status of thisMsg is false and flagged status of thisMsg is false then
            set the end of msgList to thisMsg
        end if
    end repeat
    if msgList is {} then
        display dialog "There are no read messages in this mailbox."
    else
        tell theViewer to set properties to {visible messages:msgList}
    end if
end tell
on error the errMsg number the errNmb
if the errNmb is not -128 then
    set the errTxt to "Error: " & the errNmb & ". " & the errMsg
    display dialog the errTxt buttons {"Cancel"} default button 1
else
    error number -128
end if

end try

Any help would be appreciated.

10
  • What is "tell theViewer to set properties to {visible messages:msgList}" supposed to be doing?
    – Tetsujin
    Commented Jul 10, 2015 at 12:56
  • Change the message viewer to only display the read messages.
    – apowell656
    Commented Jul 10, 2015 at 13:00
  • Read? The rest of the script is looking for Unread… anyway, that's the bit it doesn't like. It doesn't want to coerce the property, though I can't figure why
    – Tetsujin
    Commented Jul 10, 2015 at 13:02
  • I meant Unread. I have similar scripts for Read and Flagged.
    – apowell656
    Commented Jul 10, 2015 at 13:23
  • I'm guessing the visibility flag has changed, it might even now be sandboxed & that's why it isn't working. Console throws "10/07/2015 14:32:11.591 Mail[340]: [<MessageViewer 0x7f870d068d40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key focusedMessages." I don't know how to fix it, but that does seem a very roundabout way of finding unread & unflagged.
    – Tetsujin
    Commented Jul 10, 2015 at 13:32

1 Answer 1

0

From comments…

As it would appear that many people across the net are struggling & 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 & 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 " & (count of unReadMsgs) as string) & ¬
            " 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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .