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());
}