Members-only tutorial
Watch the video and get the practice sheet with membership.
About this Tutorial
Sheet Resources
Video Transcript
<div>0:00 In a previous video, I showed you this list of motivational quotes, spreadsheet Learn about spreadsheets and how they can help you organize your data effectively. Opens in new tab quotes, famous spreadsheet Learn about spreadsheets and how they can help you organize your data effectively. Opens in new tab quotes and how we got them onto this website, randomquote.card.co And every time we refresh it, we're going to get a brand new spreadsheet Learn about spreadsheets and how they can help you organize your data effectively. Opens in new tab quote from this list.<br>0:16 If you wanted to keep this private or you wanted to send this to a very special person, maybe yourself.
So, I want to show you how to do that in this video.<br>0:25 We're going to go to App Script Discover how to automate tasks in Google Sheets with Apps Script. Opens in new tab , Extensions App Script Discover how to automate tasks in Google Sheets with Apps Script. Opens in new tab , open it up and we already have the embed code from the last video here, we don't need that.<br>0:32 code already to get a random quote, but how do we email it to ourselves? The key here is we do not need the doGet Understand the doGet function and its role in web apps using Google Apps Script. Opens in new tab function Explore what functions are and how to use them in your scripts. Opens in new tab , but we do want function Explore what functions are and how to use them in your scripts. Opens in new tab emailDigly.<br>0:43 And this is pretty simple, we're going to use at the end mailApp Find out how to send emails from your Google Apps Script using MailApp. Opens in new tab .sendEmail.
And the sendEmail function Explore what functions are and how to use them in your scripts. Opens in new tab is only going to take three things.<br>0:52 We need a to, someone sending it, who we're sending it to, we need a subject, and a body of that message.<br>0:58 The to will be us, which ah whenever you're using this Apps Script Discover how to automate tasks in Google Sheets with Apps Script. Opens in new tab . We can do variable to equals, I think it's going to be session.getActiveUser.<br>1:10 This should get a email address of the user. We can always check this out by doing logger.log to and we can see if that is the case.<br>1:20 use variable subject.
We can put the random quote here if we want or we can put it in the body or both.<br>1:32 So actually I'm going to put it in both the body and the subject. And see how that goes. So when we run this for the first time we're going to have to approve it.<br>1:42 But we're going to see if we want to see this logger if this session.get.active user is really getting just the email address of whoever is creating this app script Discover how to automate tasks in Google Sheets with Apps Script. Opens in new tab which in our case is not.<br>1:52 It's going to be us. Once we authorize it, uh it will game back with this Android better sheet. Perfect.
It is exactly me.<br>2:01 This session.get.active user is getting our email address. But we do have an issue with get random quote. I think we're getting.<br>2:10 I think we need to string Learn about strings and how to manipulate text in your scripts. Opens in new tab . I think. See if this might be too much. Shh. Let's try to run it again.<br>2:30 Oh actually I think the issue is we need to string Learn about strings and how to manipulate text in your scripts. Opens in new tab the .2.2 string Learn about strings and how to manipulate text in your scripts. Opens in new tab . Thanks watching. I think that's the issue here.<br>2:46 Or actually we just need get email. We don't need to string Learn about strings and how to manipulate text in your scripts. Opens in new tab . Sorry. That was weird. But now we should just get email and if we run it we shouldn't get that.<br>2:56 Perfect.
So if we checked our email we can see it. And this is what our email looks like. The subject is the quote and the uh body is the quote.<br>3:06 It's actually a different quote in this case. Umm so what we can do is change the subject to, Today's quote.<br>3:15 We can even add new date to make it a different, absolutely different subject each and every time. We're gonna save that and run it.<br>3:26 And here we see this uhh. Umm, uhh, formatted date is here. So we can always format Get tips on formatting data in Google Sheets for better presentation. Opens in new tab this date in a nicer way.<br>3:34 We're gonna wrap Understand how to wrap text in cells for improved readability in your spreadsheets. Opens in new tab it with utilities.formatDate.
We're just gonna give it a format Get tips on formatting data in Google Sheets for better presentation. Opens in new tab here we want month month. Uhh, actually we're gonna one day day mm year.<br>3:48 And we need to end the parentheses here. And let's see if that works again. I think we need to use GMT here.<br>4:04 And maybe this. So now let's see if this works we'll save it. Make sure it's saved. This orange button going away.<br>4:13 We'll run it and should have an email. Perfect. Our date is formatted well and we only have one quote here.<br>4:20 Perfect. We're getting a random quote emailed to us. But now how do we do this every day?
Email daily is only gonna run when we click run function Explore what functions are and how to use them in your scripts. Opens in new tab .<br>4:28 Well what we can do here is go over to the left and click on triggers. We can go to the bottom right, add trigger Learn how to set up triggers to automate tasks in Google Sheets. Opens in new tab .<br>4:35 And we're gonna choose which function Explore what functions are and how to use them in your scripts. Opens in new tab to run. In our case it's gonna be emailed daily. And the event source instead of from spreadsheet Learn about spreadsheets and how they can help you organize your data effectively. Opens in new tab we're gonna use time driven.<br>4:43 We want to do it every day so we'll use day timer and we'll set a time period.
In our case we wanted before we start work so something around 5am to 6am.<br>4:54 You pick an hour and the very first time it runs it'll be a completely random time within that hour and then every time after that it'll be 24 hours later.<br>5:03 So we'll hit say leave and now I'll get an email every day uh giving me that motivational quote a random one every day uh until I turn off this trigger Learn how to set up triggers to automate tasks in Google Sheets. Opens in new tab .<br>5:16 If you're looking for the code and the quotes as well if you'd like the quotes check out the sheet down below if you're on better sheets if you're not on better sheets and watching this go join bettersheets.co and get the sheet and the script all together everything all at once.</div>