This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CHAPTER 2 - Bound to a Google Form | |
function copyMasterDocument(e) { | |
//Get form responses (teacher & document) | |
var itemResponses = e.response.getItemResponses(); | |
var teacher = itemResponses[0].getResponse(); | |
var document = itemResponses[1].getResponse(); | |
//Get file ID for document selected | |
var documents = ["Lesson plan", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CHAPTER 1 - Bound to a Google Form | |
function assignmentMaker(e) { | |
//Get latest form response (teacher, group, assignment) | |
var itemResponses = e.response.getItemResponses(); | |
var teacher = itemResponses[0].getResponse(); | |
var group = itemResponses[1].getResponse(); | |
var assignment = itemResponses[2].getResponse(); | |
//Get task for assignment selected | |
var assignments = ["Assignment #1", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//search for files | |
function example111() { | |
const files = DriveApp.getFolderById('ADD YOUR FOLDER ID HERE') | |
.searchFiles('modifiedDate > "2021-03-31"'); | |
while (files.hasNext()) { | |
var file = files.next(); | |
Logger.log(file.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Standalone script to create Form | |
function createForm() { | |
const form = FormApp.create("Brochure request"); | |
form.setTitle('Brochure request'); | |
form.setCollectEmail(true); | |
} | |
//Stored in Google Form - i.e. bound to form | |
//Send brochure PDF when form filled out | |
function example101() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get file 'Reference Doc', make PDF download link & email it. //examples.gs | |
function example91() { | |
var fileId = getFileId(); | |
var downloadUrl = 'https://docs.google.com/document/d/' | |
+ fileId + '/export?format=pdf'; | |
sendEmail(downloadUrl); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get any Google Docs in folder and add a paragraph to all of them | |
function example81() { | |
const parentFolder = DriveApp.getFolderById('ADD YOU FOLDER ID HERE'); | |
const listOfDocs = parentFolder.getFilesByType(MimeType.GOOGLE_DOCS); | |
while (listOfDocs.hasNext()) { | |
var file = listOfDocs.next(); | |
var docId = file.getId(); | |
var doc = DocumentApp.openById(docId); | |
var body = doc.getBody(); | |
body.appendParagraph("This paragraph was added automatically."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Log the name of every folder in the user's Drive | |
function example71() { | |
const folders = DriveApp.getFolders(); | |
while (folders.hasNext()) { | |
var folder = folders.next(); | |
Logger.log(folder.getName()); | |
} | |
} | |
//Get folder names within a specific folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Convert Doc to PDF | |
function example61() { | |
//Make copy of Doc | |
const masterDoc = DriveApp.getFileById('ADD YOUR DOCUMENT ID HERE'); | |
const newDoc = masterDoc.makeCopy("EXAMPLE 61 - Company document"); | |
const newDocId = newDoc.getId(); | |
//create a PDF file from this Doc | |
const pdf = DriveApp.getFileById(newDocId).getAs('application/pdf'); | |
pdf.setName(newDoc.getName() + ".pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add editor to folder | |
function example51() { | |
const folder = DriveApp.createFolder("EXAMPLE51"); | |
folder.addEditor('brgablog1@gmail.com'); | |
} | |
//Add editors to folder & don't allow them to share it | |
function example52() { | |
const folder = DriveApp.createFolder("EXAMPLE52"); | |
folder.addEditors(['brgablog1@gmail.com', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create 2 folders and file in parent folder, move file & folder1 to folder2 | |
function example41() { | |
const parentFolder = DriveApp.getFolderById('ADD YOUR FOLDER ID HERE'); | |
const folder1 = parentFolder.createFolder("EXAMPLE41-FOLDER1"); | |
const folder2 = parentFolder.createFolder("EXAMPLE41-FOLDER2"); | |
const file = parentFolder.createFile("EXAMPLE41-NEW FILE", | |
"This file has moved from one folder to another.", | |
MimeType.PLAIN_TEXT); | |
file.moveTo(folder2); | |
folder1.moveTo(folder2); |