// generated · Gmail

Auto-label + star email from one sender as Priority.

When mail from a specific person lands, I want it flagged so it never gets lost in the pile.

Automatically label every email from my manager as "Priority" and star it.

The script

copy · paste · trigger
labelPriorityFromBoss.gs
Apps Script
// Made with bulldo.gs · describe an automation, get working Apps Script.
// Fork or fix this one → https://bulldo.gs/g/label-priority-from-boss

// Label + star recent mail from one sender. Install a time-based trigger
// (every 5-15 minutes) so it sweeps shortly after mail arrives.
const BOSS = 'manager@example.com';

function labelPriorityFromBoss() {
  const label = GmailApp.getUserLabelByName('Priority') || GmailApp.createLabel('Priority');
  const threads = GmailApp.search('from:' + BOSS + ' newer_than:1d -label:Priority', 0, 50);
  threads.forEach(function (t) {
    t.addLabel(label);
    t.getMessages().forEach(function (m) { m.star(); });
  });
}

Made with bulldo.gs. Fork it to change a field, a trigger, or the edge cases — describe the change and Gnaw rewrites it.

Walkthrough

How it works

getUserLabelByName returns the Priority label if it exists; the `||` falls back to createLabel the first time, so the script is safe to run on a brand-new account.

The search query is scoped with `newer_than:1d -label:Priority` so each run only touches fresh, not-yet-labelled threads — that keeps it idempotent and cheap even on a frequent trigger.

For each thread it adds the label and stars every message. Stars are per-message in Gmail, so the inner loop covers long threads too.

Set the sender + trigger

Replace manager@example.com with the address you care about. Then add a time-based trigger (Triggers → minutes timer → every 5–15 minutes). Approve the Gmail modify scope once.

Need a different version?

Describe your sheet or inbox and the rule you want. Gnaw writes the Apps Script — fields, triggers, edge cases — in one shot.

FAQ

3 questions
Can I watch more than one sender?
Yes — change the query to `from:(a@x.com OR b@y.com)`. The rest of the script is unchanged.
Why `newer_than:1d` instead of every email ever?
It bounds each run to recent mail so you do not re-scan your whole mailbox every few minutes. A first-time backfill can be run once with a wider window.
Will it re-star threads I already handled?
No. The `-label:Priority` guard skips anything already labelled, so a thread is only touched once.