CodePy Christmas
Merry Christmas: An Introduction to Google Apps Script
What is Google Apps Script(GAS)?
GAS is a JavaScript-based platform for writing cloud applications and expanding/integrating with Google services. That probably doesn't sound very useful to the average user, but anyone with any JavaScript experience can start using GAS to automate tasks. Today we'll walk you through using a script we've written with GAS and break the commands down into pseudo-code.
CodePy Christmas GAS
This script does one simple thing: when it is Christmas, it will email you.
To use:
- Go here to open the script
- Click the 'triggers' button
- Click 'No triggers set up. Click here to add one now.'
- Change 'Hour Timer' to 'Day Timer'
- In the last drop down box select what time of day you want to receive your email
- Click save and wait for Christmas!
How it works
- var email = Session.getActiveUser().getEmail();
- Gets your (the user's) email address and save it in a variable called email
- var currentTime = new Date();
- Sets the variable currentTime to the current milliseconds since January 1st, 1970 UTC
- if ((currentTime.getMonth() == 11)&(currentTime.getDate() == 25)){
- Checks if it's Christmas
- (currentTime.getMonth() == 11)
- Checks if the current month is December(January is 0, so December is 11)
- (currentTime.getDate() == 25)
- Checks if the current day is the 25th
- &
- Checks that both the month is December and the day is the 25th (So it's only true on December 25th, Christmas)
- GmailApp.sendEmail(email, "GAS Christmas", "Merry Christmas from CodePy!");
- Only runs when above "if" statement is true
- Sends yourself an email with "GAS Christmas" as the subject and "Merry Christmas from CodePy!" in the body
Pseudo-code
What is Pseudo-code?
Pseudo-code(fake-code) is the English(or other language) interpretation of a computer program.
From Google:
" a notation resembling a simplified programming language, used in program design."
Pseudo CodePy Christmas
Do this every day:- Save the users email address
- Find out what day it is
- If it's Christmas:
- Send the user an email saying Merry Christmas
- If it isn't Christmas:
- Don't do anything
Modify Code
You can save this code to your own account and modify as you want; feel free to play around with it! Just go to file -> make a copy... to save a copy for yourself. You can find it in your Google Drive. Be aware: Unlike Google Docs, Sheets, and Slides, Apps Script does NOT auto save.
Conclusion
Thank you for following along with this tutorial and we hope you learn to use Google Apps Script!
Remember to feel free to contact us with any questions on our website, CodePy.
Comments
Post a Comment