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()}`);}
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}`);}
Returns the PageRange a collection of Page instances in the flimstrip that are
selected or null if the selection is not of type SelectionType.PAGE.
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}`,);}
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()}`);}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eSelection\u003c/code\u003e object represents the user's current selection within a Google Slide presentation, encompassing various elements like pages, shapes, text, or table cells.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to identify the type of selection, retrieve the selected elements, and access their properties.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize the \u003ccode\u003eSelection\u003c/code\u003e object to programmatically interact with and manipulate the selected content within the presentation.\u003c/p\u003e\n"],["\u003cp\u003eThis includes retrieving the selected page, page elements, table cells, or text range, allowing for customized actions based on the user's selection.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eSelection\u003c/code\u003e object enables automation and customization of Google Slides presentations based on user interactions and selections.\u003c/p\u003e\n"]]],["The document outlines how to manage selections within Google Slides using the SlidesApp. Key actions include: retrieving the current page, determining the selection type, and accessing selected elements. Methods allow retrieving selected page elements, pages, table cells, or text ranges. Each method returns a specific object type related to the selection or `null` if no selection is made or the selection does not match the method type. Authorization for `presentations` scopes is required.\n"],null,["Selection\n\nThe user's selection in the active presentation.\n\n```javascript\nconst selection = SlidesApp.getActivePresentation().getSelection();\nconst currentPage = selection.getCurrentPage();\nconst selectionType = selection.getSelectionType();\n``` \n\nMethods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------|----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [getCurrentPage()](#getCurrentPage()) | [Page](/apps-script/reference/slides/page) | Returns the currently active [Page](/apps-script/reference/slides/page) or `null` if there is no active page. |\n| [getPageElementRange()](#getPageElementRange()) | [PageElementRange](/apps-script/reference/slides/page-element-range) | Returns the [PageElementRange](/apps-script/reference/slides/page-element-range) collection of [PageElement](/apps-script/reference/slides/page-element) instances that are selected or `null` if there are no [PageElement](/apps-script/reference/slides/page-element) instances selected. |\n| [getPageRange()](#getPageRange()) | [PageRange](/apps-script/reference/slides/page-range) | Returns the [PageRange](/apps-script/reference/slides/page-range) a collection of [Page](/apps-script/reference/slides/page) instances in the flimstrip that are selected or `null` if the selection is not of type [SelectionType.PAGE](/apps-script/reference/slides/selection-type#PAGE). |\n| [getSelectionType()](#getSelectionType()) | [SelectionType](/apps-script/reference/slides/selection-type) | Returns the [SelectionType](/apps-script/reference/slides/selection-type). |\n| [getTableCellRange()](#getTableCellRange()) | [TableCellRange](/apps-script/reference/slides/table-cell-range) | Returns the [TableCellRange](/apps-script/reference/slides/table-cell-range) collection of [TableCell](/apps-script/reference/slides/table-cell) instances that are selected or `null` if there are no [TableCell](/apps-script/reference/slides/table-cell) instances selected. |\n| [getTextRange()](#getTextRange()) | [TextRange](/apps-script/reference/slides/text-range) | Returns the [TextRange](/apps-script/reference/slides/text-range) that is selected or `null` if the selection is not of type [SelectionType.TEXT](/apps-script/reference/slides/selection-type#TEXT). |\n\nDetailed documentation \n\n`get``Current``Page()` \nReturns the currently active [Page](/apps-script/reference/slides/page) or `null` if there is no active page.\n\n```javascript\nconst selection = SlidesApp.getActivePresentation().getSelection();\nconst currentPage = selection.getCurrentPage();\nif (currentPage != null) {\n Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`);\n}\n```\n\nReturn\n\n\n[Page](/apps-script/reference/slides/page)\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/presentations.currentonly`\n- `https://www.googleapis.com/auth/presentations`\n\n*** ** * ** ***\n\n`get``Page``Element``Range()` \nReturns the [PageElementRange](/apps-script/reference/slides/page-element-range) collection of [PageElement](/apps-script/reference/slides/page-element) instances that are\nselected or `null` if there are no [PageElement](/apps-script/reference/slides/page-element) instances selected.\n\n```javascript\nconst selection = SlidesApp.getActivePresentation().getSelection();\nconst selectionType = selection.getSelectionType();\nif (selectionType === SlidesApp.SelectionType.PAGE_ELEMENT) {\n const currentPage = selection.getCurrentPage();\n const pageElements = selection.getPageElementRange().getPageElements();\n Logger.log(`Number of page elements selected: ${pageElements.length}`);\n}\n```\n\nReturn\n\n\n[PageElementRange](/apps-script/reference/slides/page-element-range)\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/presentations.currentonly`\n- `https://www.googleapis.com/auth/presentations`\n\n*** ** * ** ***\n\n`get``Page``Range()` \nReturns the [PageRange](/apps-script/reference/slides/page-range) a collection of [Page](/apps-script/reference/slides/page) instances in the flimstrip that are\nselected or `null` if the selection is not of type [SelectionType.PAGE](/apps-script/reference/slides/selection-type#PAGE).\n\n```javascript\nconst selection = SlidesApp.getActivePresentation().getSelection();\nconst selectionType = selection.getSelectionType();\nif (selectionType === SlidesApp.SelectionType.PAGE) {\n const pageRange = selection.getPageRange();\n Logger.log(\n `Number of pages in the flimstrip selected: ${\n pageRange.getPages().length}`,\n );\n}\n```\n\nReturn\n\n\n[PageRange](/apps-script/reference/slides/page-range)\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/presentations.currentonly`\n- `https://www.googleapis.com/auth/presentations`\n\n*** ** * ** ***\n\n`get``Selection``Type()` \nReturns the [SelectionType](/apps-script/reference/slides/selection-type).\n\n```javascript\nconst selection = SlidesApp.getActivePresentation().getSelection();\nconst selectionType = selection.getSelectionType();\nif (selectionType === SlidesApp.SelectionType.CURRENT_PAGE) {\n const currentPage = selection.getCurrentPage();\n Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`);\n}\n```\n\nReturn\n\n\n[SelectionType](/apps-script/reference/slides/selection-type)\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/presentations.currentonly`\n- `https://www.googleapis.com/auth/presentations`\n\n*** ** * ** ***\n\n`get``Table``Cell``Range()` \nReturns the [TableCellRange](/apps-script/reference/slides/table-cell-range) collection of [TableCell](/apps-script/reference/slides/table-cell) instances that are selected\nor `null` if there are no [TableCell](/apps-script/reference/slides/table-cell) instances selected.\n\n```javascript\nconst selection = SlidesApp.getActivePresentation().getSelection();\nconst selectionType = selection.getSelectionType();\nif (selectionType === SlidesApp.SelectionType.TABLE_CELL) {\n const currentPage = selection.getCurrentPage();\n const tableCells = selection.getTableCellRange().getTableCells();\n const table = tableCells[0].getParentTable();\n Logger.log(`Number of table cells selected: ${tableCells.length}`);\n}\n```\n\nReturn\n\n\n[TableCellRange](/apps-script/reference/slides/table-cell-range)\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/presentations.currentonly`\n- `https://www.googleapis.com/auth/presentations`\n\n*** ** * ** ***\n\n`get``Text``Range()` \nReturns the [TextRange](/apps-script/reference/slides/text-range) that is selected or `null` if the selection is not of type\n[SelectionType.TEXT](/apps-script/reference/slides/selection-type#TEXT).\n\nThe [TextRange](/apps-script/reference/slides/text-range) represents two scenarios:\n\n1. Range of text selected. For example if a shape has text \"Hello\", and \"He\" is selected,\nthe returned range has [TextRange.getStartIndex()](/apps-script/reference/slides/text-range#getStartIndex()) = 0, and [TextRange.getEndIndex()](/apps-script/reference/slides/text-range#getEndIndex()) =\n2.\n\n2. Cursor position. For example if a shape has text \"Hello\", and cursor is after \"H\",\n(\"H\\|ello\"), the returned range has [TextRange.getStartIndex()](/apps-script/reference/slides/text-range#getStartIndex()) = 1 and [TextRange.getEndIndex()](/apps-script/reference/slides/text-range#getEndIndex()) = 1.\n\n```javascript\nconst selection = SlidesApp.getActivePresentation().getSelection();\nconst selectionType = selection.getSelectionType();\nif (selectionType === SlidesApp.SelectionType.TEXT) {\n const currentPage = selection.getCurrentPage();\n const pageElement = selection.getPageElementRange().getPageElements()[0];\n const textRange = selection.getTextRange();\n Logger.log(`Text selected: ${textRange.asString()}`);\n}\n```\n\nReturn\n\n\n[TextRange](/apps-script/reference/slides/text-range)\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/presentations.currentonly`\n- `https://www.googleapis.com/auth/presentations`"]]