Thursday, March 22, 2012

Go to next unread message in Mail via keyboard

A long standing annoyance in Mail is that there is no keyboard shortcut to skip to the next message. I found in hints.macworld.com a apple script that will jump to the next unread mail on ctr-n.
I changed the script to jump to the last item and not the first, as I like to read my messages by chronological order.
try
 tell application "Mail"
  activate
  tell the front message viewer
   set unreadMessages to (the messages whose ¬
    read status is false) as list
   if (count of unreadMessages) is not 0 then
    set selected messages to {the last item of unreadMessages}
   else
    beep
   end if
  end tell
 end tell
on error error_message
 beep
 display dialog "Error looking for next unread message: " & ¬
  return & return & error_message buttons {"OK"} default button 1
end try
To have this script activated, instead of copying it to the mail script folder as suggested in the article, I created a new service with "no input" in "Mail.app" that will run the apple script on the top. Saved the service, and added the shortcut ctrl-n in the keyboard settings.

1 comment :

  1. This script works great in Mavericks, but doesn't work in Yosemite.
    In Yosemite, no message is selected.
    Does anyone have any guess why that might be?

    ReplyDelete