Hide and unhide slides based on relation to key slides

86 views
Skip to first unread message

Anthony Harlan

unread,
Sep 12, 2023, 10:56:41 PM9/12/23
to Google Apps Script Community
Greetings!

I'm making an announcements slide show, and I have 5 key slides called "Read Monday", "Read Tuesday", etc. then there are some slides after the Friday section that are a closing.

I'd like to write a script to run at midnight that does the following:

today = "Read "+day_of_week.index
tomorrow = "Read "+day_of_tomorrow.index

for slide in "Read Monday".index to "Closing".index{
  slide.hide
  if today < index < tomorrow {
    slide.unhide
  }


I don't know how to name specific slides so that I can reference them later and find their index. I can have users put comments in the reader notes, but I don't know how to parse the reader notes either. What ideas do you have?

cwl...@gmail.com

unread,
Sep 13, 2023, 12:25:03 PM9/13/23
to Google Apps Script Community
The way I do it is, use the main text of the title in the slide, and then I name them based on the text. Whenever the slides are opened, the script runs to be able to relocate those slides (or put it on a timed trigger like you have it). 

Just ensure each slide's main title text is unique: 

slide.png

Then my code looks something like this:
const documentProperties = PropertiesService.getDocumentProperties();
let wedPageID = documentProperties.getProperty('WEDNESDAY_PAGEID');

//get all slides, iterate through them looking for the textbox that contains "Wednesday" (in this example)
async function getPageIDs() {
  var ss = SlidesApp.getActivePresentation();
  var slides = ss.getSlides();
  slides.forEach( (slide, i) => {
      var shapes = slide.getShapes();
        shapes.forEach( (shape, j) => {
          var shapeText = shape.getText().asString();
            if ( shapeText === "Wednesday\n") {
              documentProperties.setProperty('WEDNESDAY_PAGEID', slide.getObjectId())
            }
        })
    })
}

the above was just to get the slideIds into storage for use in your actual update scripts:
async function updateWed() {
  var ss = SlidesApp.getActivePresentation();
  var slide = ss.getSlideById(wedPageID);
  slide.selectAsCurrentPage();
...
//your code here if this slide gets updated automagically
 
...
//refresh the slide
  ss.getSlideById(wxMapPageID).refreshSlide()
}

This works for me for updating daily slides that get briefed. Briefers just push the buttons in a sidebar and the content is updated automatically... no more copy/pasting.. lol
Reply all
Reply to author
Forward
0 new messages