Automatically label lingering emails with this Google Apps Script

I try to keep my inbox clean, and for the most part I do a pretty good job at it. There’s one bad habit I have, though. I star emails in Gmail so I’ll remember to follow up with them later, and then I never get around to it. Emails just keep getting pushed further down the list and piling up. I can’t deal with all emails right away, but after a while they just stick around because I’m avoiding making a decision on them. What I need is a way to automatically to something give myself a little nudge after a certain amount of time. A little push that will remind me that those emails aren’t going to just answer themselves.

After looking at a lot of solutions (Gmail filters,, etc), I finally discovered Google Apps Scripts. You can write javascript functions to do all kinds of automations in your inbox. You can then set the functions to run on a timer. It was exactly what I was looking for.

I was able to write a couple of functions to automatically add a label to any items that were in my inbox that also had a star label. When I remove the star, or archive the email, the label is removed. Here’s what the output looks like.

deal with me label-1

Here’s how I set it up

Go to, and create a new project. I called mine “Add nagging label for old starred items”

Paste in the following code

[updated 4/23/13 to fix a bug that was causing un-starred threads to not have the label automatically removed]

Save the script, then test to make sure the scripts are working by selecting the “addNaggingLabels” or “removeNaggingLabels” functions from the dropdown in the script editor toolbar, then clicking the arrow to run them. You’ll be asked to allow the script to be run on your inbox before you can test it out. You should only have to do that step once.

When the “Deal with me” label gets created, it won’t be red by default. You’ll have to go find it in the left sidebar of your Gmail inbox and click the arrow next to it to manually change the color to red (or some color you really hate. Whatever will be the most motivating).

Finally, click the “triggers” icon, and set up the following triggers so both functions run every hour.

Deal with me gmail label

That’s really all there is to it. Now, I get a nice big red label automatically added to any stale starred items. It doesn’t totally prevent things from piling up, but it helps give me that little prod to make an effort to keep things tidy.

5 Comments on “Automatically label lingering emails with this Google Apps Script”

  1. Nice work! My fear is that this just takes the problem one level deeper. The general problem is one of backlogs. Your inbox itself isn’t a backlog problem because you use stars, but then the starred messages get backlogged, so now you have meta-stars (dealwithme labels). Where will it end?? 🙂

    Btw, in my own google apps scripting I set up triggers programmatically, in case you want to see my code for that. And you can also publish your script so others can use it as a one-click install. (I did that with my gmail snooze script: )

    Anyway, my prediction would be that what starts as an effective “little prod”, as you say, will gradually degenerate to wolf-crying, but if you tell me otherwise then I think I will try this out!

    • Robby Macdonell says:

      Well, when you put it like that (meta-stars) it does sound a little silly… 🙂 Fair observation, though.

      It’s working well for me right now, but I’ll admit that could be due to the novelty of it. We’ll have to see in a couple months once the newness has worn off. I’d say the difference between the star and the label (in this system) is the star is an explicit filing (“I’m putting THIS over HERE to deal with later”) where the label really acts as a persistent notification that something has stagnated into an undesirable state because I’ve just been avoiding it. In my opinion, anything that sticks around that long should either be dealt with immediately or I should use something like your snooze script to get it completely out of my inbox until later.

  2. Emily says:

    I love this idea but when I tried to set it up, the script works but the label is grey instead of red so it doesn’t stand out as much. Can I change that somehow?

    • Robby Macdonell says:

      Sure, you should be able to change the label color by finding the label in the right sidebar (under the “inbox”, “sent mail”, etc… links). Hover your mouse over it, then there should be a dropdown arrow that appears next to it. Click that, and you should be able to set the color to whatever you like. I agree, the red definitely helps it to feel more urgent.

  3. Emily says:

    simple fix robby, thank you! happy to give this a go 🙂