Category: Google Apps Script

  • Google Apps Script Slide Creator

    This script logs a greeting, creates a new Google Slide with a timestamped title, and appends sample text to it while logging the document URL

    Click to view script…
    function myTestSlideScript() {
      // Log a simple greeting message
      Logger.log("Hello, Google Apps Script!");
    
      // Get and log the active user's email address
      var userEmail = Session.getActiveUser().getEmail();
      Logger.log("Active user: " + userEmail);
    
      // Create a new Google Slides presentation with a unique name based on the current date and time
      var presentation = SlidesApp.create("Test Presentation " + new Date());
    
      // Get the first (default) slide of the presentation
      var slide = presentation.getSlides()[0];
    
      // Try to set the title and subtitle placeholders on the default title slide, if they exist
      var titlePlaceholder = slide.getPlaceholder(SlidesApp.PlaceholderType.CENTERED_TITLE);
      if (titlePlaceholder) {
        titlePlaceholder.asShape().getText().setText("Test Presentation");
      }
      
      var subtitlePlaceholder = slide.getPlaceholder(SlidesApp.PlaceholderType.SUBTITLE);
      if (subtitlePlaceholder) {
        subtitlePlaceholder.asShape().getText().setText("Created by: " + userEmail);
      }
    
      // Optionally, append another slide with additional details
      var additionalSlide = presentation.appendSlide(SlidesApp.PredefinedLayout.TITLE_AND_BODY);
      
      // Set the title of the additional slide
      var titleShape = additionalSlide.getShapes()[0];
      titleShape.getText().setText("Additional Slide");
    
      // Set the body text of the additional slide
      var bodyShape = additionalSlide.getShapes()[1];
      bodyShape.getText().setText("This slide was added by the script.\nActive user email: " + userEmail);
    
      // Log the URL of the created presentation so you can easily open it
      Logger.log("Presentation created: " + presentation.getUrl());
    }

  • Google Apps Script Sheet Creator

    This script logs a greeting, creates a new Google Sheet with a timestamped title, and appends sample text to it while logging the document URL

    Click to view script…
    function myTestScript() {
      // Log a simple greeting message
      Logger.log("Hello, Google Apps Script!");
    
      // Get and log the active user's email address
      var userEmail = Session.getActiveUser().getEmail();
      Logger.log("Active user: " + userEmail);
    
      // Create a new Google Sheet with a unique name based on the current date and time
      var spreadsheet = SpreadsheetApp.create("Test Spreadsheet " + new Date());
      var sheet = spreadsheet.getActiveSheet();
    
      // Append some rows to the sheet
      sheet.appendRow(["This spreadsheet was created by a test script in Google Apps Script."]);
      sheet.appendRow(["Active user email:", userEmail]);
    
      // Log the URL of the created spreadsheet so you can easily open it
      Logger.log("Spreadsheet created: " + spreadsheet.getUrl());
    }
  • Google Apps Script Document Creator

    This script logs a greeting, creates a new Google Document with a timestamped title, and appends sample text to it while logging the document URL

    Click to view script…
    function myTestScript() {
      // Log a simple greeting message
      Logger.log("Hello, Google Apps Script!");
    
      // Get and log the active user's email address
      var userEmail = Session.getActiveUser().getEmail();
      Logger.log("Active user: " + userEmail);
    
      // Create a new Google Document with a unique name based on the current date and time
      var doc = DocumentApp.create("Test Document " + new Date());
      var body = doc.getBody();
    
      // Append some paragraphs to the document
      body.appendParagraph("This document was created by a test script in Google Apps Script.");
      body.appendParagraph("Active user email: " + userEmail);
    
      // Log the URL of the created document so you can easily open it
      Logger.log("Document created: " + doc.getUrl());
    }