Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created December 26, 2021 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanaikech/8eb87e6499631a79dade7d4f83e372f7 to your computer and use it in GitHub Desktop.
Save tanaikech/8eb87e6499631a79dade7d4f83e372f7 to your computer and use it in GitHub Desktop.
Inverting Selected Objects on Google Slides using Google Apps Script

Inverting Selected Objects on Google Slides using Google Apps Script

This is a sample script for inverting the selected objects on Google Slides using Google Apps Script.

I have the case that I want to invert the selected objects on Google Slides. This sample script can be achieved this goal using Google Apps Script.

Sample script

Please copy and paste the following script to the script editor of Google Slides, and save the script. And, please select the objects on the Slide and run the function main(). By this, the selected objects are inverted.

function main() {
  const s = SlidesApp.getActivePresentation().getSelection();
  const selections = s.getPageElementRange();
  const obj = selections
    ? selections
        .getPageElements()
        .reduce((o, e) => ((o[e.getObjectId()] = true), o), {})
    : {};
  const page = s.getCurrentPage();
  page.selectAsCurrentPage();
  page.getPageElements().forEach((e) => {
    if (!obj[e.getObjectId()]) e.select(false);
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment