Pages: [1]   Go Down
  Print  
Author Topic: Ask the Script Doctor: Solving Mail problems  (Read 387 times)
HCK
Global Moderator
Hero Member
*****
Posts: 79425



« on: October 29, 2012, 11:05:36 am »

Ask the Script Doctor: Solving Mail problems
   




   

AppleScript is a great tool for automating the apps you use daily on your Mac—if you can figure out the proper code. We're here to help: We've asked scripting and Automator expert Ben Waldie to solve some reader problems using AppleScript. The idea is not just to provide specific solutions for specific problems, but also to demonstrate some general principles and provide sample scripts that, with a little tinkering, you can adapt to solve a bunch of other problems, too. First up: A few questions about Mail. Fire up AppleScript Editor (/Applications/Utilities) and follow along.


Q: I have tons of mailbox folders in Mail, some of them nested several levels deep. Over the years I've filed thousands of messages in them, some of which I never marked as read. Is there a way to go through all those folders and mark all of the messages as read?


Absolutely. You want to tell Mail to set the read status attribute of every unread message in your Inbox, local mailboxes, and mailboxes on your mail server to false. Be prepared, though: Depending on the number of messages and mailboxes you have, this procedure may take a while to run. And since individual AppleScript commands time out if they don't finish within 2 minutes, you might also get an error. That's why it's a good idea to enclose your script in a timeout wrapper to prevent such errors. The script below allows each action up to 5 minutes to finish; feel free to increase the timeout period if necessary.

--Allow up to 5 minutes
with timeout of 300 seconds
  tell application "Mail"
    -- Process all unread messages in the inbox
    set read status of every message of inbox where its read status = false to true
    -- Process all unread messages on your local Mac
    set read status of every message of every mailbox where its read status = false to true
    -- Process all unread messages on your mail server
    set read status of every message of every mailbox of every account where its read status = false to true
  end tell
end timeout
To read this article in full or to leave a comment, please click here
      

http://www.macworld.com/article/2012277/ask-the-script-doctor-solving-mail-problems.html
   
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: