A while back, Android added the ability for some of its notifications to be directly acted upon from the notification shade, such as archiving a Gmail message. More recently, this same functionality came to Android Wear. It can be very handy if you immediately know that you'll want to archive a message without reading it, but frustrating if you (like me) were bothered that it didn't actually mark the message as read.

In the past, we covered MarkAsRead, an Android app that adds a "Read" button to the notification. This works on Android devices (if you only need one Google account), but nowhere else. In my opinion, this should be (and hopefully eventually will be) built into Android itself, but until then, there's another route.

Mike Crittenden came up with this simple Google Apps script that scans your Gmail account every minute for "unread" messages that are located anywhere other than your inbox and then marks them as read. This allows you to simply archive the email from the notification, knowing that the "unread" part will go away on its own. And it's actually really simple.

Here's how it's done.

  1. Head to script.google.com to start a script.
  2. Choose to create a script for Gmail in the little popup.
  3. Delete all the sample code it gives you.
  4. 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?

Pretty awesome, Mike, pretty awesome. And since it's tied to your Google account, it'll automatically work on any device that Gmail does.

Advertisement

One thing to be aware of is that the script has a limit of 100 threads, meaning it will fail if you have more than 100 unread archived threads in your mailbox. To get around this, manually do a search in Gmail for "label:unread -label:inbox" and mark everything as read. This will give the script a clean slate for the future (thanks genericbrandx!).

Marking Gmail read with Apps Script | Mike Crittenden