Selection

The user's selection in the active presentation.

```javascript
const selection = SlidesApp.getActivePresentation().getSelection();
const currentPage = selection.getCurrentPage();
const selectionType = selection.getSelectionType();
```

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/slides/selection#getCurrentPage()` | `https://developers.google.com/apps-script/reference/slides/page|null` | Returns the currently active `https://developers.google.com/apps-script/reference/slides/page` or `null` if there is no active page. |
| `https://developers.google.com/apps-script/reference/slides/selection#getPageElementRange()` | `https://developers.google.com/apps-script/reference/slides/page-element-range|null` | Returns the `https://developers.google.com/apps-script/reference/slides/page-element-range` collection of `https://developers.google.com/apps-script/reference/slides/page-element` instances that are selected or `null` if there are no `https://developers.google.com/apps-script/reference/slides/page-element` instances selected. |
| `https://developers.google.com/apps-script/reference/slides/selection#getPageRange()` | `https://developers.google.com/apps-script/reference/slides/page-range|null` | Returns the `https://developers.google.com/apps-script/reference/slides/page-range` a collection of `https://developers.google.com/apps-script/reference/slides/page` instances in the flimstrip that are selected or `null` if the selection is not of type `https://developers.google.com/apps-script/reference/slides/selection-type#PAGE`. |
| `https://developers.google.com/apps-script/reference/slides/selection#getSelectionType()` | `https://developers.google.com/apps-script/reference/slides/selection-type` | Returns the `https://developers.google.com/apps-script/reference/slides/selection-type`. |
| `https://developers.google.com/apps-script/reference/slides/selection#getTableCellRange()` | `https://developers.google.com/apps-script/reference/slides/table-cell-range|null` | Returns the `https://developers.google.com/apps-script/reference/slides/table-cell-range` collection of `https://developers.google.com/apps-script/reference/slides/table-cell` instances that are selected or `null` if there are no `https://developers.google.com/apps-script/reference/slides/table-cell` instances selected. |
| `https://developers.google.com/apps-script/reference/slides/selection#getTextRange()` | `https://developers.google.com/apps-script/reference/slides/text-range|null` | Returns the `https://developers.google.com/apps-script/reference/slides/text-range` that is selected or `null` if the selection is not of type `https://developers.google.com/apps-script/reference/slides/selection-type#TEXT`. |

## Detailed documentation

### `getCurrentPage()`

Returns the currently active `https://developers.google.com/apps-script/reference/slides/page` or `null` if there is no active page.

```javascript
const selection = SlidesApp.getActivePresentation().getSelection();
const currentPage = selection.getCurrentPage();
if (currentPage != null) {
  Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`);
}
```

#### Return


`https://developers.google.com/apps-script/reference/slides/page|null`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/presentations.currentonly`
- `https://www.googleapis.com/auth/presentations`

*** ** * ** ***

### `getPageElementRange()`

Returns the `https://developers.google.com/apps-script/reference/slides/page-element-range` collection of `https://developers.google.com/apps-script/reference/slides/page-element` instances that are
selected or `null` if there are no `https://developers.google.com/apps-script/reference/slides/page-element` instances selected.

```javascript
const selection = SlidesApp.getActivePresentation().getSelection();
const selectionType = selection.getSelectionType();
if (selectionType === SlidesApp.SelectionType.PAGE_ELEMENT) {
  const currentPage = selection.getCurrentPage();
  const pageElements = selection.getPageElementRange().getPageElements();
  Logger.log(`Number of page elements selected: ${pageElements.length}`);
}
```

#### Return


`https://developers.google.com/apps-script/reference/slides/page-element-range|null`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/presentations.currentonly`
- `https://www.googleapis.com/auth/presentations`

*** ** * ** ***

### `getPageRange()`

Returns the `https://developers.google.com/apps-script/reference/slides/page-range` a collection of `https://developers.google.com/apps-script/reference/slides/page` instances in the flimstrip that are
selected or `null` if the selection is not of type `https://developers.google.com/apps-script/reference/slides/selection-type#PAGE`.

```javascript
const selection = SlidesApp.getActivePresentation().getSelection();
const selectionType = selection.getSelectionType();
if (selectionType === SlidesApp.SelectionType.PAGE) {
  const pageRange = selection.getPageRange();
  Logger.log(
      `Number of pages in the flimstrip selected: ${
          pageRange.getPages().length}`,
  );
}
```

#### Return


`https://developers.google.com/apps-script/reference/slides/page-range|null`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/presentations.currentonly`
- `https://www.googleapis.com/auth/presentations`

*** ** * ** ***

### `getSelectionType()`

Returns the `https://developers.google.com/apps-script/reference/slides/selection-type`.

```javascript
const selection = SlidesApp.getActivePresentation().getSelection();
const selectionType = selection.getSelectionType();
if (selectionType === SlidesApp.SelectionType.CURRENT_PAGE) {
  const currentPage = selection.getCurrentPage();
  Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`);
}
```

#### Return


`https://developers.google.com/apps-script/reference/slides/selection-type`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/presentations.currentonly`
- `https://www.googleapis.com/auth/presentations`

*** ** * ** ***

### `getTableCellRange()`

Returns the `https://developers.google.com/apps-script/reference/slides/table-cell-range` collection of `https://developers.google.com/apps-script/reference/slides/table-cell` instances that are selected
or `null` if there are no `https://developers.google.com/apps-script/reference/slides/table-cell` instances selected.

```javascript
const selection = SlidesApp.getActivePresentation().getSelection();
const selectionType = selection.getSelectionType();
if (selectionType === SlidesApp.SelectionType.TABLE_CELL) {
  const currentPage = selection.getCurrentPage();
  const tableCells = selection.getTableCellRange().getTableCells();
  const table = tableCells[0].getParentTable();
  Logger.log(`Number of table cells selected: ${tableCells.length}`);
}
```

#### Return


`https://developers.google.com/apps-script/reference/slides/table-cell-range|null`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/presentations.currentonly`
- `https://www.googleapis.com/auth/presentations`

*** ** * ** ***

### `getTextRange()`

Returns the `https://developers.google.com/apps-script/reference/slides/text-range` that is selected or `null` if the selection is not of type
`https://developers.google.com/apps-script/reference/slides/selection-type#TEXT`.

The `https://developers.google.com/apps-script/reference/slides/text-range` represents two scenarios:

1. Range of text selected. For example if a shape has text "Hello", and "He" is selected,
the returned range has `https://developers.google.com/apps-script/reference/slides/text-range#getStartIndex()` = 0, and `https://developers.google.com/apps-script/reference/slides/text-range#getEndIndex()` =
2.

2. Cursor position. For example if a shape has text "Hello", and cursor is after "H",
("H\|ello"), the returned range has `https://developers.google.com/apps-script/reference/slides/text-range#getStartIndex()` = 1 and `https://developers.google.com/apps-script/reference/slides/text-range#getEndIndex()` = 1.

```javascript
const selection = SlidesApp.getActivePresentation().getSelection();
const selectionType = selection.getSelectionType();
if (selectionType === SlidesApp.SelectionType.TEXT) {
  const currentPage = selection.getCurrentPage();
  const pageElement = selection.getPageElementRange().getPageElements()[0];
  const textRange = selection.getTextRange();
  Logger.log(`Text selected: ${textRange.asString()}`);
}
```

#### Return


`https://developers.google.com/apps-script/reference/slides/text-range|null`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/presentations.currentonly`
- `https://www.googleapis.com/auth/presentations`