Google Slides and Apps Script

Hi,

I would like to create a very specific page numbering on my slides.

I would like to use Apps Scipt for this
But I find few sources

I can't get the position of a slide in the presentation?
There is an AutoText Class but I can't find any example to use it

Can you help me?
Thanks

Solved Solved
0 9 2,684
1 ACCEPTED SOLUTION

Stephane_fr
Google Developer Expert
Google Developer Expert

This will work

function slidePageNumber() {
  let current =  SlidesApp.getActivePresentation().getSelection().getCurrentPage().getObjectId();

  const pages = SlidesApp.getActivePresentation().getSlides();
  for(let i = 0 ; i < pages.length ; i++){
    if(pages[i].getObjectId() == current){
      console.log(i+1)
      return ;
    }
  }
}

Stรฉphane

View solution in original post

9 REPLIES 9

Stephane_fr
Google Developer Expert
Google Developer Expert

Hi

Not sure if that will fit your needs but the example of the progress bar could help maybe ?

https://developers.google.com/apps-script/add-ons/editors/slides/quickstart/progress-bar

Stรฉphane

Hi Stephane,

Yes, I have already seen this example but it does not give me the solution for the numbers of each slide.

A simple trick:
I select some text on a slide,
I would like to know the number of this slide ?
How do I do this?

Thanks

Stephane_fr
Google Developer Expert
Google Developer Expert

Not sure to understand but when you are on edit mode when you are on a slide on the left nav bar, the selected slides have yellow border and there is number displayed at the top left.

You want something in presentation mode ?

stรฉphane

No no, I speak about apps script.

 I write this in a bounded script in order to get the selected page

var currentPage = SlidesApp.getActivePresentation().getSelection().getCurrentPage();

 But, how I can retrieve the page number ? 

Stephane_fr
Google Developer Expert
Google Developer Expert

This will work

function slidePageNumber() {
  let current =  SlidesApp.getActivePresentation().getSelection().getCurrentPage().getObjectId();

  const pages = SlidesApp.getActivePresentation().getSlides();
  for(let i = 0 ; i < pages.length ; i++){
    if(pages[i].getObjectId() == current){
      console.log(i+1)
      return ;
    }
  }
}

Stรฉphane

Yes, I'm OK with that

I thought there was a native function in the Google Slides API that allows you to retrieve the position of the Slide, but NO !! Very strange !

In order to continue my research on specific page numbering, I am also looking for example scripts that use the AutoText class

What can I do with this AutoText class?

Thanks

 

Stephane_fr
Google Developer Expert
Google Developer Expert

I don't know, on my side I don't invest  lot of time in apps script Google Slides project so I don't really know the functions available.

Stรฉphane

No worries Stephane !

Maybe someone else will have information?

Thanks

Top Labels in this Space
Top Solution Authors