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.
Asked
Active
Viewed 32 times
0

Omar Saucedo
- 11
- 1
-
Do you want to use one editor in particular? (Spreadsheets, Slides, Forms, etc..) – Aerials Jun 09 '20 at 09:07
-
Yes, I am using the SpreadsheetApp – Omar Saucedo Jun 09 '20 at 16:28
-
Please share the code you have tried so far – Aerials Jun 10 '20 at 08:29
-
I didn't mess with code that much, because I couldn't get the trigger to fire, I thought the problem had more to do with some configuration. Anyway, I posted it in the answer. Thanks a lot for your time and help. – Omar Saucedo Jun 10 '20 at 16:27
1 Answers
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.

Omar Saucedo
- 11
- 1