简体   繁体   中英

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当前行为

Expected behaviour预期行为

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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM