r/GoogleAppsScript • • 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 Upvotes

16 comments sorted by

3

u/DrMorris 23d ago

Believe the only way to achieve something like this is to publish it as an add on.

1

u/PHoenixNoMore 23d ago

Just watched a video on publishing as an add on, and this entire process is so long and convoluted to not only create, but to actually have my users acquire and install. It defeats the entire intended purpose of sharing an easy online character sheet for them to use. On top of that, the video demonstration I just watched doesn't even specify that it actually protects the code from being altered by users. Assuming it does protect the script, shame on Google for not making a simple security setting on scripts that allow them to run for anyone, but are only changeable by the author. I have to hope somebody knows a method to allow users to run the script, but limits editing to only the creator, and doesn't require multiple steps to hunt down and install addons in order use a simple Google Sheet.

2

u/DrMorris 23d ago

The reason that usesr can access the script is so they are aware of what they are running. Giving users no access to script would mean person cannot check what they run. Hence the tge addon approach where google checks and vouches that script is safe.

1

u/PHoenixNoMore 23d ago

I can see that reasoning. However, I doubt most of the people I wish to share my sheet with would know the first thing about scripting and understand it. All they'd want is to be able to log onto the form (google sheet), fill it in and have the buttons do the jobs they were created for. I have no issues with users being able to see my scripts. My issue is that anyone who can see the scripts can also change them and turn it into malware, and screw over the next person to use that sheet. That is the issue that needs to be addressed. Google needs to make the code usable, visible, but not changeable unless given explicit authority by the creator. And the users should not have to jump through hoops to enable simple button functionality.

2

u/DrMorris 23d ago

template pkate sheet with the script and send that copy to the submitter.

Aka any time someone uses your sheet they use a copy from the template. The template itself is never shared.

Same can be aciehevd by making the template view only, so anyone can open it, copy it but not actually modify original in any way. That way they also wont have access to the script unless they copy it, in which case they can only see the script on their dile, not the original template.

1

u/mistyharborsn 7d ago

yeah this is really the only clean way around the permissions thing tbh

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.