Skip to content

Instantly share code, notes, and snippets.

@ViViDboarder
Last active March 10, 2020 05:04
Show Gist options
  • Save ViViDboarder/10307575 to your computer and use it in GitHub Desktop.
Save ViViDboarder/10307575 to your computer and use it in GitHub Desktop.
Gmail Snooze
/*
Gmail Message Snoozing
Quick implementation to allow snoozing of unread messages in Gmail
Usage:
The move unread emails into a snooze label for the desired snooze time. After
the specified time, the message should be moved back into your inbox. This will
only effect unread emails to prevent messages from continuing to bounce back
Setup:
* Copy and paste this into a new Google Script in Google Drive
* Run setupSnooze() to create labels
* Add triggers for each method set to the indicated time in their comments
* Enjoy
Notes:
Possibly will decide to remove items from the specified label after moving to inbox
*/
function setupSnooze() {
GmailApp.createLabel('Snooze');
GmailApp.createLabel('Snooze/Hour');
GmailApp.createLabel('Snooze/Tonight');
GmailApp.createLabel('Snooze/Tomorrow');
GmailApp.createLabel('Snooze/This Weekend');
}
// Move to Inbox anything that has been in Snooze/Hour for more than an hour
// Trigger set to run on a minute timer every 15 min
function snoozeHour() {
var snooze = 'Hour';
// Get all threads in Snooze/Hour that are holder than an hour
var threads = GmailApp.search('label:"Snooze/' + snooze + '" older_than:1h is:unread -in:Inbox');
GmailApp.moveThreadsToInbox(threads);
Logger.log('Snooze/%s: Just unsnoozed %s threads', snooze, threads.length);
}
// Move to Inbox anything that is in Snooze/Tonight in the evening
// Trigger set to run on a day timer at 6pm
function snoozeTonight() {
// Get all threads in Snooze/Tonight
unSnooze('Tonight');
}
// Move to Inbox anything that is in Snooze/Tomorrow the next morning
// Trigger set to run on a day timer at 7am
function snoozeTomorrow() {
// Get all threads in Snooze/Tomorrow
unSnooze('Tomorrow');
}
// Move to Inbox anything that is in Snooze/This Weekend when the weekend starts
// Trigger set to run on a week timer at 7am on Saturday
function snoozeThisWeekend() {
// Get all threads in Snooze/This Weekend
unSnooze('This Weekend');
}
// Takes a label to unsnooze
function unSnooze(snooze) {
var query = Utilities.formatString('label:"Snooze/%s" is:unread -in:Inbox', snooze);
var threads = GmailApp.search(query);
GmailApp.moveThreadsToInbox(threads);
Logger.log('Snooze/%s: Just unsnoozed %s threads', snooze, threads.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment