Build an Automator Quick Action To Snooze Email

Want to clear your inbox but need to set reminders to get back to email messages later on? You can use this Automator Quick Action to set a reminder with a mink to the message and then archive the message.

function run(input, parameters) {
	
	// set up applications
	var Mail = Application("Mail");
	Mail.includeStandardAdditions = true;
	var Reminders = Application("Reminders");
	var SystemEvents = Application('System Events');
	
	// get the selected messages
	var messages = Mail.selection();
	
	// loop through all messages
	for(var i=0;i<messages.length;i++) {
	
		// get the subject, sender and message id
		var subject = messages[i].subject();
		var sender = messages[i].sender();
		var id = messages[i].messageId();
		
		// prompt for subject modifications and the snooze time
		var dialogResult = Mail.displayDialog('Email Snooze Reminder Title',
			{ defaultAnswer: subject + ' from ' + sender,
			buttons: ['4 PM Today', '4 Hours From Now', 'Cancel'],
			defaultButton: '4 PM Today',
			cancelButton: 'Cancel',
			withTitle: 'Mail Snooze' });

		// calculate the due date time
		var due = new Date();
		if (dialogResult.buttonReturned == '4 PM Today') {
			due.setHours(16);
			due.setMinutes(0);
			due.setSeconds(0);
		} else if (dialogResult.buttonReturned == '4 Hours From Now') {
			due.setHours(due.getHours() + 4);
		} else {
			return; // cancelled, so quit
		}
		
		// get the new title
		reminderTitle = dialogResult.textReturned;
		
		// create a new reminder and add it
		var newReminder = Reminders.Reminder({ name: reminderTitle, body: "message://<"+id+">", dueDate: due});

		Reminders.lists.byName("Email Snooze").reminders.push(newReminder);
		
	}
		
	// send a Control+Command+a to archive the selected messages
	SystemEvents.keystroke('a', { using: ['control down', 'command down'] });
}

Comments: 17 Responses to “Build an Automator Quick Action To Snooze Email”

    Brad Simmons
    3 weeks ago

    Your excellent “Snooze Email” program is a real help, even for this 85 year old. Thank you for making the instructions so clear and understandable. The service you offer is a real blessing. Brad

    Wei
    3 weeks ago

    I tried this but got an error: “Can’t get object”, when running the Javascript. I wonder what went wrong.

    Wei
    3 weeks ago

    I figured this out. The script assumes that a Reminder list “Email Snooze” already exists. I needed to create this list first for it to work.

    3 weeks ago

    Wei: Yes, I say that at 5:52.

    Jörg Brandt
    2 weeks ago

    Hi, what a helpful thing I was looking for a long time! Thanks a lot and greetings from Germany!

    Jörg Brandt
    2 weeks ago

    Just one thing: I tried to set the reminder at 9pm in the script, which doesn’t work. It still shows me 4pm. How to change this?

    2 weeks ago

    Jörg: Look at the script carefully. You have to change those things in several places.

    Lawrence Moore
    2 weeks ago

    This looks like a great convenience. Assuming I install the script on both computers, will I encounter any issues if I access my three email accounts from two computers, a laptop and an iMac?

    2 weeks ago

    Lawrence: It should act just like if you did these steps manually on one computer. Try it and see.

    Lawrence Moore
    2 weeks ago

    This looks like a great convenience. Assuming I install the script on both computers, will I encounter any issues if I access my three email accounts from two computers, a laptop and an iMac?

    Lawrence Moore
    2 weeks ago

    Thanks Gary.
    Oops, I hit the wrong button.

    Jonathan
    2 weeks ago

    This is fantastic. I would however, like to set reminder to 9am the following day (as one of the options). I can see how to edit the time but not the date. Any ideas anyone?

    2 weeks ago

    Jonathan: Try to add + 1 to the line:
    var due = new Date()

    Jonathan
    2 weeks ago

    That’s excellent thank you. I tried other things, but not that!

    Jörg
    1 week ago

    Found it. I had to change “due.setHours(16) to (21). Thanks!

    Dean Kutzler
    7 days ago

    This is awesome!! How do I fix: The action “Run JavaScript” encountered an error: “Error: Error: Automator Workflow Runner (WorkflowServiceRunner, Email Action Required) is not allowed to send keystrokes.”?

    7 days ago

    Dean: Did you allow permissions like I show in the video?

Leave a New Comment Related to "Build an Automator Quick Action To Snooze Email"

:
:
:
0/500 (500 character limit -- please state your comment succinctly and do not try to get around this limit by posting two comments)