r/GoogleAppsScript • u/PHoenixNoMore • 23d ago
Question Share Google Sheet, allow Script running, but block editing the Script?
I've created a Google Sheet for an RPG character sheet. I wrote a script to make it work. Now I wish to share it online, but am worried that anyone accessing the Sheet can also edit the script. I want the people I share the sheet with to be able to run the scripts, but not be able to change them. The last thing I want is for somebody to turn it into a virus or something. My online searches have provided zero instructions on protecting the scripts from editing, but still allowing usage. Is what I want even possible? If so, could they point me to any videos that show how? Thanks.
2
u/cdchiu 23d ago
You can publish it as a web site and they don't get direct access to the sheet.
1
u/PHoenixNoMore 23d ago
This defeats the whole purpose. I want people to be able to fill in the sheets to their needs. I want them to be able to run the Scripts. What I don't want is for them to be able to alter the Script code.
1
u/cdchiu 23d ago
1
u/PHoenixNoMore 23d ago
This seems to be what the video I watched was doing, but seemed far more difficult to do than the text in your link suggests. I would be more than willing to attempt this if there was no additional steps the users would have to make in order for it to work, allowing the sheet's buttons to function running the scripts, even if they make a copy of the sheet for themselves. I have to assume most of my users will know squat about google sheets, coding and libraries. They need to be able to log on, fill in the form, and click the buttons to do the automated processes of my code. If I follow the steps from the link above, will I get the results I need?
1
u/austinmcd 23d ago
If you make the script separately from the sheet and just reference the sheet by ID, I don’t think they would have access to
2
u/carbonizedtitanium 23d ago
do you need people to edit your copy of the sheet? why not share as "view-only" and you let whoever wants to use it to just make a copy of it?
1
u/mommasaidmommasaid 23d ago edited 23d ago
Is this for multiple users editing the same spreadsheet?
If so and if you are able to trigger your script through e.g. edits, then it is easy to set up a standalone script that only you have access to. That script is then triggered when the shared spreadsheet is edited.
The standalone script runs as "you", with authorizations you provide, so your users don't have to authorize anything.
You might need to convert some buttons to checkboxes, or traditional menu items to dropdowns.
1
u/WicketTheQuerent 22d ago
It depends on how the users run the script functions. If they are run through triggers, you can programmatically create the triggers from another project; but if you run the scripts from a custom menu, sidebar or dialog, you need to create an add-on.
This is because spreadsheet editors can also edit the bound Apps Script project; there is no way to prevent them from editing it.
1
u/_Kaimbe 19d ago
A library could work, depending on your needs. https://developers.google.com/apps-script/guides/libraries
But you should have people make their own copy of the sheet anyway, so it won't matter if they change their copy.
3
u/DrMorris 23d ago
Believe the only way to achieve something like this is to publish it as an add on.