Marking Gmail read with Apps Script

Recent versions of Android give you the ability to Archive an email right from the notification bar. I use this like 30 times a day, for emails that I can tell from the subject that I don’t need to read. It’s awesome.

The only issue is that these message stay unread, and seeing a bunch of unread messages in my archive or labels annoys me, so every morning I search “label:unread” and mark all as read. It’s a total first world problem, but annoying nonetheless.

I’ve been looking for some sort of app or something to auto-mark-as-read any messages not in the inbox for months now. Then someone recently pointed me to Google Apps Script and 10 minutes later I had a script running which automatically marks all archived messages as read every minute. I was blown away at how easy this was.

Here’s how it’s done:

  • Head to script.google.com to start a script.
  • Choose to create a script for Gmail in the little popup.
  • Delete all the sample code it gives you.
  • Replace it with this (written using the API reference):
function markArchivedAsRead() {
  var threads = GmailApp.search('label:unread -label:inbox');
  GmailApp.markThreadsRead(threads);
};
  • Save the project with File > Save.
  • Add a new version using File > Manage Versions and enter “initial version” then submit that.
  • Do a test run using Run > markArchivedAsRead and be sure and authorize the app when it asks you to.
  • Add a new trigger using Resource > Current Project’s Triggers and choose to run the above function every minute (or hour or day or whatever if you want to be nice to Google’s servers).
  • Save the script again and exit. Don’t worry, it will keep running.

And you’re done. It will continue to run every minute until you stop it. How awesome is that?

Update: Some people are reporting an error which says “This operation can only be applied to at most 100 threads. (line 3, file “Code”)”. To fix this, you have to manually do a search for “is:unread” and mark all of them as read before running the script, so that it starts with a clean slate. The script can only process 100 threads per run, so if you give it more than 100 on the first run, that’ll obviously bust it.

Hey, maybe you should follow me on Twitter!

search previous next tag category expand menu location phone mail time cart zoom edit close