I have already explained in a previous post what Google Apps Script or GAS is. Will use this post to explain the steps needed to write a script and walk you through a simple script that creates a new Google Document and email the link of the created document.
There are about 3 ways of creating a Google Apps Script from Google Drive.
There are about 3 ways of creating a Google Apps Script from Google Drive.
- Go to drive.google.com. You will have to log in with your Google Apps / Gmail account. From Google Drive, choose Create -> More -> Script
- Go to script.google.com.
- You can create a script from an existing spreadsheet. Once you have spreadsheet open, go to Tools -> Script Editor. All 3 options will open the same window for you to create a script for; Blank Project, Script as Web App, Drive, Spreadsheet, Document, Gmail, Calendar and Sites.
Select Blank Project from the opened window and delete the placeholder code in your new script. Copy and paste the code below into the Script Editor.
function createAndSendDocument() {
// Create a new document with the title 'Hello World'
var doc = DocumentApp.create('Hello World');
// Add a paragraph to the document
doc.appendParagraph('This document was created by my first Google Apps Script.');
// Save and close the document
doc.saveAndClose();
// Get the URL of the document
var url = doc.getUrl();
// Get the email address of the active user - that's you
var emailAddress = Session.getActiveUser().getEmail();
// Send yourself an email with a link to the document
GmailApp.sendEmail(emailAddress,
'Hello from my first Google Apps Script!',
'Here is a link to a document created by my ' +
'first Google Apps Script: ' + url);
}
After you paste the code into the Script Editor, click the Save icon. You'll be prompted to rename your project. Enter a name and then click OK. Now that you've created the script, execute the script!
On your first run it will request for access to run the script, just normal routine security stuff, read the message and continue. More details about Google’s apps scripts security policy can be found here. Now go ahead and run the script again.
Next we will write some generic scripts which will do the following:
- Add / Delete Calendar Events
- Send Bulk Emails
- Gmail Snooze Labels
- Adding Menu Buttons
Comments
Post a Comment