Created
December 14, 2024 01:07
-
-
Save wecsam/c11cfcde59fc5129087702ed44564f5a to your computer and use it in GitHub Desktop.
A Google Slides app script that skips/unskips slides based on the user's input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
SlidesApp.getUi() | |
.createMenu("Scripts") | |
.addItem("Skip/Unskip by Numbers", "unskipByNumbers") | |
.addToUi(); | |
} | |
/** Prompts the user for slide numbers. Unskips all of the specified slides. Skips the rest. */ | |
function unskipByNumbers() { | |
var ui = SlidesApp.getUi(); | |
var response = ui.prompt("Enter slide numbers to unskip (all others will be skipped), separated by commas and/or whitespace:"); | |
if (response.getSelectedButton() !== ui.Button.OK) { | |
return; | |
} | |
// Get the slide numbers to unskip in descending order numerically. | |
// Subtract 1 from each slide number to convert from 1-based index to 0-based index. | |
var toUnskip = response.getResponseText().split(/[\s,;]+/g).map(s => parseInt(s) - 1).filter(n => !isNaN(n)); | |
toUnskip.sort((a, b) => b - a); | |
Logger.log(toUnskip); | |
var slides = SlidesApp.getActivePresentation().getSlides(); | |
for (var i = 0; i < slides.length; ++i) { | |
// The next slide to unskip will always be the last one in `toUnskip`. | |
// If `toUnskip` is empty, all remaining slides should be skipped. | |
if (toUnskip.length && i === toUnskip[toUnskip.length - 1]) { | |
slides[i].setSkipped(false); | |
toUnskip.pop(); | |
} else { | |
slides[i].setSkipped(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment