Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Slides: Select a slide from Apps Script

I'm trying to select a newly created slide with the API call selectAsCurrentPage() (using Google Apps Script):

var slide = SlidesApp.getActivePresentation().appendSlide(SlidesApp.PredefinedLayout.TITLE_AND_BODY);
slide.selectAsCurrentPage();

But it seems, that the selectAsCurrentPage() doesn't work as I expected - it loads that slide into the main edit area, but the slide is not selected in the left timeline panel (it's not decorated with a grey rectangle as if I select the slide manually, instead there is a black line on top of the timeline):

Current behaviour Current behaviour

Expected behaviour Expected behaviour

So, how it is possible to select that slide also in the left timeline?

like image 694
Dominik Palo Avatar asked Nov 20 '25 02:11

Dominik Palo


1 Answers

Unfortunately, in the current stage, there are no method for directly achieving the situation yet. So how about this workaround? The flow of this workaround is as follows. I think that there might be several workarounds. So please think of this as just one of them.

  1. Append a slide using appendSlide().
    • This is from your script.
  2. Insert a text box as a dummy object.
    • I think that anything objects can be used for this situation.
  3. Select the dummy object.
  4. Remove the dummy object.

By this flow, the appended slide is selected. The sample script is as follows.

Sample script:

var slide = SlidesApp.getActivePresentation().appendSlide(SlidesApp.PredefinedLayout.TITLE_AND_BODY);
var obj = slide.insertTextBox(""); // Added
obj.select(); // Added
obj.remove(); // Added

References:

  • select()
  • remove()

If this was not the result you want, I apologize.

like image 140
Tanaike Avatar answered Nov 21 '25 17:11

Tanaike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!