Drive Title Copier

September 13, 2017Productivity, Portfolioproductivity, google drive, automation

A colleague had a ton of student work that she needed names in the titles. She had the fear that she would have to open each document and manually change every title.

Never fear! Google Apps Script to the rescue!

If there is a repeatable task, it is definitely a safe bet that it can be automated with a little bit of code. In this tutorial I am demonstrating an example of exactly that.

function copyTitles() {
  var folderId = '<<<PUT THE NAME OF THE FOLDER WITH YOUR DOCUMENTS HERE>>>';
  var folder = DriveApp.getFolderById(folderId);
  var files = folder.getFilesByType(MimeType.GOOGLE_DOCS);

  while (files.hasNext()) {
    var file = files.next();
    var fileId = file.getId();
    var fileName = file.getName();

    DocumentApp.openById(fileId)
      .getBody()
      .insertParagraph(0, fileName)
      .setAlignment(DocumentApp.HorizontalAlignment.CENTER)
      .setHeading(DocumentApp.ParagraphHeading.HEADING1);
  }
}

What are some of the recurring tasks that you wish you could automate? Leave me some comments below!

jordan rhea

Jordan Rhea - I’m a front-end web developer. Follow me at @rheajt if you want to talk, discuss, or fix any of my code! I am passionate about using JavaScript in Google projects, but there are many more applications. I want to learn them all.