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 link to the message and then archive the message.
▶ You can also watch this video at YouTube.
▶ Watch more videos about related subjects: Automator (50 videos).
▶ You can also watch this video at YouTube.
▶ Watch more videos about related subjects: Automator (50 videos).
Video Transcript
Hi, this is Gary with MacMost.com. Today let me show you how to make an automator QuickAction that will allow you to snooze email.
MacMost is brought to you thanks to a great group of more than 800 supporters. Go to MacMost.com/patreon. There you can read more about the Patreon Campaign. Join us and get exclusive content and course discounts.
So I often get asked about this and this is actually a functionality that I wanted as well. I want to be able to snooze an email message. So an email comes into my Inbox. I want to do something with it but not right now. Maybe at the end of the day. Maybe tomorrow. Maybe in a few hours. It would be great if there was a way that I could get it out of my Inbox but still have a reminder to go and do something with that email message later on. Now you could do this manually. Here I've got the Reminders app open. I can drag and drop an email from my inbox into the Reminders app. You could see here there's actually a link to that email message. I can actually double click it and it opens up that email message in Mail. It evens works if I were to Archive the email and then go to Reminders, double click on the icon there, and now I can open up that email even though it's in my Archive. Then I can go to this Reminder here. Set a Remind me on Day and set a Time and have it remind me about that email.
That's a lot of steps every time you need to do that. So the idea here is to Automator and see if we can do it in one or two quick steps. So I'm going to launch Automator and I'm going to want to create a QuickAction. A QuickAction will allow us to assign a keyboard shortcut to it. Then this workflow is going to receive No Input in just the Mail app. That's the only place we're going to use it. The only action in the workflow is going to be a bit of JavaScript. So I'm going to drag over the default run JavaScript action here and this is where our script will go. This is going to be a really long tutorial if I were to build it step-by-step. So I'm going Paste in my results here and then walk you through it.
So this is enclosed in the standard default function you get when you add the Run JavaScript action. Now first I need to define three things that I'm going to be accessing during this script. The first one is the Mail app. So that's simply Mail equals Application Mail. I'm going to use include standard additions so I can control Mail with scripting. Then I need to do the same thing for the Reminders app since I'm going to be saving a new reminder. I'm also going to get SystemEvents which will allow me to issue keyboard commands. I'm going to use that in the very last step here. Now the idea here is to select messages in Mail and then use this keyboard shortcut. So I'm going to get the messages that are selected, usually it will just be one message but this will actually work if you've selected multiple messages. Next I'm going to loop through each of the messages in this list. Now this does two things for us. First if you have more than one message selected it will do it for each message. But also if you have no messages selected nothing will happen. We don't have to check to see if a message is selected because this loop will simply not go through even once if there are no messages in this list. Then I'm going to get three bits of information about the message. The Subject, the Sender, and the Message ID. Now that's all I really need to create the reminder. I want to put the subject and the sender in the text of the reminder and the message ID I'm going to use to link to the message.
However, the piece of information I don't have is how long until I get a reminder. Now I could just hard code a set amount of time like 4 hours or 24 hours into this. But instead I'm actually going to ask for a time. I'm going to give two options and also a cancel button that will simply just cancel this whole operation. So I'm going to use Display dialogue. But I'm going to do even more than just ask for the time. I'm actually going to show the Subject and then the word From and Sender and this will be text there. Now I could just leave that there and that will be the text of the reminder. But I could also edit it. So if I want to leave a note to myself or I want to say something different than the subject line I could actually change it here. I'll demonstrate that when I run this. Now we've got three buttons. One says 4 PM today, another 4 hours from now, and another is Cancel. The idea here is for me 4 PM is a good time to get back to email that I may not have had time to answer earlier in the day. It may be a different time for you. Four hours from now allows me to snooze it past that. Maybe it's past 4 PM already or maybe I want to get to it sooner than 4 PM. So I've got two different types of times there. So next I'm going to take which button I click and calculate a time for the reminder to show me a notification. So if I selected 4 PM today it's going to take the current date and then it's going to set the hour to 16, which is 4 PM. Then minutes and seconds to zero. So if it's January 15th at 10:15 AM it's going to take January 15th but reset the hour to 4 PM, minutes to zero, seconds to zero. On the other hand if I chose 4 hours from now then it simply is going to add 4 hours to the current time. If I chose Cancel then it's actually going to return. It's going to quit the entire thing and stop doing what it's doing. So even if I have multiple things selected if I choose Cancel for any of them it will just cancel out. That will prevent me from making a mistake. I'm not locked in to actually setting the reminder once I've triggered this keyboard shortcut.
Now I want to get the title of the reminder. Now before I passed into the dialogue the Subject, the word From, and the word Sender. Now that will actually come out of the dialogue and I would put it into Reminder Title. But I also have the opportunity to change that text while it's in the dialogue. Next I'm going to create a new reminder object. I'm going to set its name to the Reminder Title. In the body I'm going to add something special. I'm going to use the term message colon slash slash and then surround it by less than and greater than symbols I'm going to put that message ID. It turns out that this will create a link in Reminders that then will open up that email message. It's identifying it by ID so it doesn't matter if it's still in the Inbox, if it's in an Archive folder, or some other folder. Then we're going to add it to our Reminders List called email Snooze. So that's the name of the Reminders list that I created to hold these. So you want to make sure you've created a Reminders List with that exact name or any name that you choose as long as it matches.
Now the last thing the script does is optional. I didn't want to have to Archive the message after activating this script. I wanted to automatically Archive. There are several different ways to do this. But the one that seemed to work the best is simply to trigger the Archive shortcut in Mail. So this is just going to simulate a command control a, which will Archive the messages that are selected. Now that's because my workflow is to Archive every email I get. If you have a different workflow like you file each email message into a specific Mailbox, or maybe you leave them in your Inbox then you're going to want to leave this out.
Now let's Save this and I'm going to save it as Mail Snooze and since it's a QuickAction I don't get a choice to where it is saved. It's going to save to the Special Services folder in my Library folder. Now in the Mail app if I go to Mail, Services I'll see Mail Snooze. Before we use it let's assign a keyboard shortcut to it. So in System Preferences I'm going to go to Keyboard and then Shortcuts and then App Shortcuts and add a new one. I'm going to set the Application to just Main and I'm going to give it the exact name of the menu item which is Mail Snooze. This must match what you see in the Menu Bar exactly. The keyboard shortcut I'm going to use Control Command and A, just like archive but I'm going to Shift. So now I have two keyboard commands that are kind of similar Control Command and A will archive a message. But adding Shift to it will also add this reminder. So now that I've added that I can check in Mail, Services and I can see that the keyboard shortcut has been added.
So let's try it out. I'll do Shift Control Command and A and you could see it comes up with my dialogue here. There's the Title and it says From and then who it's from. I can choose 4 PM today which is the default so I can just hit return, or 4 hours from now, or Cancel. I'll choose the default by just hitting Return. Now the thing I haven't done is set permissions. So, Mail app wants to control reminders; is that okay. Yes. Now Mail app wants to access reminders. OK. Now the last part is Mail app wants to control system events. Remember to send that keyboard shortcut. So I'll hit OK. Now I get an error because you can't actually just OK that permission. You have to go and set it up inside of System Preferences on your own. So let's do that. I'm going to go to Security and Privacy and then Accessibility. I'm going to Unlock and here you can see I have to enable Mail app. So now it will work the next time I do it which we'll test out in a minute here.
But first let's see if the first part of that script works. It should have created a reminder. I'll go to Reminders, Email Snooze. There it is. There's the name and the note has this link in it. You can see it's set to today, 4 PM. I'm going to select it and delete it. Let's give it another try now that we've granted permissions for keyboard control. So I'll try the same keyboard shortcut again. It's going to ask me here what I want to call it. But let's rename it. You can see it's already selected there. So I can just rename it to something that might make more sense to me. This time I'll go to 4 hours from now, and you could see it archived it fine this time now that I've given it permissions. Here in my email snooze reminders you could see it has set the time for the reminder for exactly four hours from now and there's the link. Now let's try the link out. Remember, in Mail now it's no longer in the Inbox. It's been Archived. So if I click here to select the reminder you can see now this is a link. I can click on it. It will launch Mail and you could see that message has been brought up even though it's no longer in the Inbox. So now I can respond to it. Now that I've taken care of this I can click here to indicate that I'm done with this reminder.
So I'll include the full script to this at this post at MacMost.com so you can easily copy and paste this into your own Automator action and modify it to suit your needs. Hopefully, in addition to being able to use this as is you can use parts of this to accomplish your own tasks in other Automator workflows.
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'] }); }
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
I tried this but got an error: "Can't get object", when running the Javascript. I wonder what went wrong.
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.
Wei: Yes, I say that at 5:52.
Hi, what a helpful thing I was looking for a long time! Thanks a lot and greetings from Germany!
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?
Jörg: Look at the script carefully. You have to change those things in several places.
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: It should act just like if you did these steps manually on one computer. Try it and see.
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?
Thanks Gary.
Oops, I hit the wrong button.
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?
Jonathan: Try to add + 1 to the line:
var due = new Date()
That's excellent thank you. I tried other things, but not that!
Found it. I had to change "due.setHours(16) to (21). Thanks!
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.”?
Dean: Did you allow permissions like I show in the video?
Hi Gary
Its very useful tool, however what do I have to add to the script if I want to define specific Date & Time ?
Thanks and greeting from Israel
Eyal: The first line where the "due" variable is set you can put a specific date there using JavaScript. But if you want a while interface to appear to ask you pick a time and a date, that will take a lot of work. Probably best to just use the Reminders app unless you are a good coder.
I get an execution error - Error: Error: Can't get object.
I have allowed permission & verified
Mail is listed under reminders.
I script runs & get the dialog box with the email info and displays correctly, then it does not matter which of the two buttons I select it come up with this error.
Under Accessibility mail was not listed so I added. I tried to close mail and it refuse to close and would not allow the system to reboot. Eventually mail closed, so I rebooted
Still get this error.
Scott: You just need to check and recheck everything. If you still can't get it to work, perhaps find a programmer friend who can help you debug it firsthand.
Hi Gary, great solution! I work with groups in my reminder, so the script wouldn't be run, if the list are lying in a group. Have you a tip for me, how the code line must look like, with a group-path?
Cheers, from Germany
Marco: I don't think Groups will make a difference. But try it and see. You can check out the documentation in Script Editor to try something different, but it will take work.
Hi Gary,
I was experimenting to add a "This Saturday" button but my JavaScript knowledge is very limited. May you just give me a hint how to calculate the variable starting from today (the time may be the same) ? The way I tried it doesn't work :(
My code example inside 'smaller-than' and 'greater-than-signs' disappeared. Here it is: due.setDate((6 - due.getDate())*24); I was tempting to calculate the difference from the value of today's weekday and Saturday (6)…
Thomas: Maybe use .getDay() and get the current day of the week, subtract that from 6 to get how many days to add.
Gary: Thanks for your help. I finally found a way to get my mail snoozed until a special weekday. This code replaces the "4 Hours From Now" section in your example:
} else if (dialogResult.buttonReturned == 'Until Saturday') {
var dueDay = 6;
var diff = due.getDay() - dueDay;
if (diff > 0) {
due.setDate(due.getDate() + 6);
} else if (diff < 0) {
due.setDate(due.getDate() + ((-1) * diff))
}
Fantastic! Now I can delete Spark which keeps losing my emails.
Re:
Jonathan: Try to add + 1 to the line:
var due = new Date()
I couldn't get this to work, so I made this change:
if (dialogResult.buttonReturned == '9 AM Tomorrow') {
due.setDate(due.getDate() + 1);
due.setHours(09);
due.setMinutes(0);
due.setSeconds(0);
This seems to work.
The automation has started looping; I deleted it and put in a new one with no changes but it repeats the dialogue several times before archiving the email and then quitting. I end up with a pile of identical reminders.
Ben: Are you selecting a message before running it?
This is good. I've been looking for something like this. Thank you.
Question though. Is it possible to change things in that java script to have it ask you the date and time on when you'd like it to be sent?
Thank you again.
Brian: Yes, it will just take a lot more work to build that. If you are an experienced programmer, it should be no problem. If not, you may want to team up with a coder to get it done.
Hi Gary,
I copy-pasted the code but it fails with an execution error: "Error: Error: Can't get object." which doesn't indicate in which line the problem is. Can you please help with this?
Thanks,
Oh, stupid! have just seen the comment from Wei, 11 months ago & fixed it :D