0

Specifically, I want to use the onSelectionChange(e) event to show a sidebar depending on what's in the selected cell. The problem is: the project I am working on is a standalone script. So I want to know if there is a way to use the onOpen event (for example) and check if the script is being run from a spreadsheet and somehow 'inject' the trigger.

1 Answers1

1

I was trying something pretty much like in the documentation, but I never got it to fire, I guess because it was a standalone script.

const onSelectionChange = (e) => {
  Logger.log(`onSelectionChange triggered: ${e.toString()}`);
  const { range } = e;
  if (range.getNumRows() === 1 && range.getNumColumns() === 1) {
    range.setBackground('green');
  }
};

So the actual solution for me was to create a new document with clasp. Using the command:

npx clasp create --type sheets --title "foo" --rootDir ./dist

and then uploading the script to this new project.