How to get activated column's index in App Script?

In your situation, how about the following sample script? In order to retrieve the current activated column number, I thought that SpreadsheetApp.getActiveRange().getColumn() might be able to be used.

Sample script:

const activatedColumnIndex = SpreadsheetApp.getActiveRange().getColumn();
SpreadsheetApp.getActiveSheet().autoResizeColumn(activatedColumnIndex);
  • In this case, when this script is run, the current activated column number is retrieved and the retrieved number is used for autoResizeColumn.

References:

  • getActiveRange() of Class SpreadsheetApp
  • getColumn() of Class Range