Is there a way to insert the current date and/or time in Google Slides?
1 Answer
In case someone else finds this, I was able to automate this using Google Apps Scripts which is available under the Tools menu. Here is the script I made which updates any text box that has the description field set to "$date" to the current date every time the presentation is opened.
function onOpen() {
var date = Utilities.formatDate(new Date(), "PST", "M/d/yyyy");
var pattern = "\\b\\d{1,2}/\\d{1,2}/\\d{4}\\b";
var slides = SlidesApp.getActivePresentation().getSlides();
var slidesLength = slides.length;
for (var i = 0; i < slidesLength; i++) {
var shapes = slides[i].getShapes();
var shapesLength = shapes.length;
for (var j = 0; j < shapesLength; j++) {
if (shapes[j].getDescription() == "$date") {
var textRange = shapes[j].getText();
textRange.clear();
textRange.insertText(0, date);
}
}
}
}
-
Using this onOpen() fails at SlidesApp.getActivePresentation().getSlides(), presumably because getActivePresentation() can't run in AuthMode.NONE when the slide deck loads. I cannot figure out how to get it to run on open as per lucidchart.com/techblog/2017/12/07/… even tho I modified the GoodIntegratedApp example and put it outside the onOpen() function.– Eric DJun 28, 2020 at 22:26