Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adding Slide Page Link to Shape using Google Apps Script

Adding Slide Page Link to Shape using Google Apps Script

This is a sample script for adding the slide page link to the shape using Google Apps Script.

When I use Google Slides, there is the case that I want to jump to the specific slide on the same Google Slides. And, I have the case that I want to jump from the last slide to the 1st slide. In those cases, I had manually added the slide page link to each shape. But when the number of slides are large, I thought that when a script for achieving this is prepared, it will be useful. So I created this.

Demo

Sample script:

// In this case, these values are the text in the shape. You can see this at Demo.
const jumpList = [
  "Jump to Slide 1",
  "Jump to Slide 2",
  "Jump to Slide 3",
  "Jump to Slide 4",
  "Jump to Slide 5",
];

const slides = SlidesApp.getActivePresentation().getSlides();
const obj = jumpList.reduce(
  (o, e, i) => Object.assign(o, { [e]: slides[i] }),
  {}
);
slides.forEach((e) =>
  e.getShapes().forEach((s) => {
    const text = s.getText().asString().trim();
    if (jumpList.includes(text)) s.setLinkSlide(obj[text]);
  })
);
  • In this sample script, the text in the shape is used for the identification for the slide page link. But you can also the title and description of shape by modifying the script.

  • When you want to remove all links from shapes in the Google Slides, you can also use the following script.

    SlidesApp.getActivePresentation()
      .getSlides()
      .forEach((e) => e.getShapes().forEach((s) => s.removeLink()));

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment