The user's selection in the active presentation.
constselection=SlidesApp.getActivePresentation().getSelection();constcurrentPage=selection.getCurrentPage();constselectionType=selection.getSelectionType();
Methods
Method | Return type | Brief description |
---|---|---|
get | Page | Returns the currently active Page or null if there is no active page. |
get | Page | Returns the Page collection of Page instances that are selected or null if there are no Page instances selected. |
get | Page | Returns the Page a collection of Page instances in the flimstrip that are selected or null if the selection is not of type Selection . |
get | Selection | Returns the Selection . |
get | Table | Returns the Table collection of Table instances that are selected or null if there are no Table instances selected. |
get | Text | Returns the Text that is selected or null if the selection is not of type Selection . |
Detailed documentation
getCurrentPage()
Returns the currently active Page
or null
if there is no active page.
constselection=SlidesApp.getActivePresentation().getSelection();constcurrentPage=selection.getCurrentPage();if(currentPage!=null){Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`);}
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/presentations.currentonly
https://www.googleapis.com/auth/presentations
getPageElementRange()
Returns the Page
collection of Page
instances that are selected or null
if there are no Page
instances selected.
constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.PAGE_ELEMENT){constcurrentPage=selection.getCurrentPage();constpageElements=selection.getPageElementRange().getPageElements();Logger.log(`Number of page elements selected: ${pageElements.length}`);}
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/presentations.currentonly
https://www.googleapis.com/auth/presentations
getPageRange()
Returns the Page
a collection of Page
instances in the flimstrip that are selected or null
if the selection is not of type Selection
.
constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.PAGE){constpageRange=selection.getPageRange();Logger.log(`Number of pages in the flimstrip selected: ${pageRange.getPages().length}`,);}
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/presentations.currentonly
https://www.googleapis.com/auth/presentations
getSelectionType()
Returns the Selection
.
constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.CURRENT_PAGE){constcurrentPage=selection.getCurrentPage();Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`);}
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/presentations.currentonly
https://www.googleapis.com/auth/presentations
getTableCellRange()
Returns the Table
collection of Table
instances that are selected or null
if there are no Table
instances selected.
constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.TABLE_CELL){constcurrentPage=selection.getCurrentPage();consttableCells=selection.getTableCellRange().getTableCells();consttable=tableCells[0].getParentTable();Logger.log(`Number of table cells selected: ${tableCells.length}`);}
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/presentations.currentonly
https://www.googleapis.com/auth/presentations
getTextRange()
Returns the Text
that is selected or null
if the selection is not of type Selection
.
The Text
represents two scenarios:
1. Range of text selected. For example if a shape has text "Hello", and "He" is selected, the returned range has Text
= 0, and Text
= 2.
2. Cursor position. For example if a shape has text "Hello", and cursor is after "H", ("H|ello"), the returned range has Text
= 1 and Text
= 1.
constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.TEXT){constcurrentPage=selection.getCurrentPage();constpageElement=selection.getPageElementRange().getPageElements()[0];consttextRange=selection.getTextRange();Logger.log(`Text selected: ${textRange.asString()}`);}
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/presentations.currentonly
https://www.googleapis.com/auth/presentations