'Google apps script: Google Slide - exporting selected slides to a new slide presentation

I am trying to figure out a way to export selected slides to a new slide presentation. After holding ctrl and selecting multiple slides in the film strip (in the screenshot example it is slide 2,3,4) how would I export only those selected slides to a new deck presentation?

I found an older question on stack answered by User Tanaike (Google app script: exporting active slide (google slides) as PDF) that exports the the active slide in view and converts it to PDF, but no matter what I did to edit the script it would only copy over a single slide or return an error when I ran an edited script. I was not able to edit the code so that it would export all the selected slides.

Thank you in advance for your help. Copying the part of Tanaike's code I was using as reference.

    function myFunction() {

  // 1. Retrieve the active slide.
  const s = SlidesApp.getActivePresentation();
  const activeSlide = s.getSelection().getCurrentPage().asSlide();

  // 2. Create a temporal Google Slides.
  const temporalSlides = SlidesApp.create("temporalSlides");

  // 3. Copy the active slide to the temporal Google Slides.
  temporalSlides.insertSlide(0, activeSlide);

  // 4. Delete the initial slide in the temporal Google Slides.
  temporalSlides.getSlides()[1].remove();
  temporalSlides.saveAndClose();
}

screenshot



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source