Google Scripts in Spreadsheet - google-apps-script

Is there a way to have a spreadsheet in Google Drive where the script is protected from modification / editing? Does anyone know if that is an option in the Script editor?
Another thing I'd like to ask. How does one do source control for the codes in their Google scripts?
Thanks.

WRT privacy / protection of scripts: Refer to the comments and answers on this question: How to protect the Apps Script code in a Google spreadsheet?.
Source Control? See Backing up Gapps source. The version tracking in the script editor is rudimentary, so you should consider doing source control outside - you'll have to get used to copy & paste.

No you can't do it.
The script runs with the document permissions.
If you have Edit permissions on the document, you have edit permission on the script too.

Here's the Google spreadsheet developer guide.
https://developers.google.com/apps-script/reference/spreadsheet/

Related

Sharing doesn't work on Google Apps Script Editor

I am working on Google Apps Script. I want to share the Google Apps Script Editor to another account.I use Chrome browser.
I clicked File > Sharing in the editor. But I got this error:
I tried to remove all the cache and cookies and histories from the browser. but, same.
If you want to share a script bound to spreadsheet you need to share the spreadsheet itself
It is no possible to share a bound script is the spreadsheet is not shared
If the spreadsheet is shared, there is no need to explicitly share the script

Run Google Apps Script without authentification

I have Google Sheet open for everyone
https://docs.google.com/spreadsheets/d/1H3slbaG_p6u3NihRDJfPECGF_teVoi-DGyJkDM5japg/edit#gid=0
And I have Google Apps Script that generates XML based on this Sheet.
https://script.google.com/macros/s/AKfycbza3jI02E9zQDB-VoVBrxpHTUq8QUY2lVrUd1bGuf5q5L7jOybq/exec
So can I allow everyone get result of this script without authentification?
Yes, you can allow everyone use your script by doing following changes :
Making Spreadsheet Open for everyone (Give Edit rights to Anyone with Link)
Attach script to that Spreadsheet (Open that Spreadsheet>Tools>Script Editor) and execute the script at least once to authorize it on your behalf.
If this doesn't work or you need anymore assistance then kindly let me know in comments.

Avoid Open ScriptEditor of Google Spreasheet

In my google spreadsheet, my scripts and custom function already work. However, I want to prevent other users from accessing the script editor, but they should be able to access/run the custom menus.
Is this possible, if so could you point me in the right direction?
If the user has Edit access to the document they have access to the script. If you need to remove access to the script you will need to publish it as an add-on. This is a pretty simple process especially if you are publishing it for your own work domain.
https://developers.google.com/apps-script/add-ons/

Use script in all spreadsheets

I'm in the process of completely switching from excel to google spreadsheets. I'm writing a set of simple scripts that will help me be productive. Is there any way to make it so that these scripts are inherited by all google spreadsheets that I open (new + existing) from my google account? I know I can publish an add-in, but short of this...
In other words, when I open a new google spreadsheet I'd love to have my custom menus & functions automatically be available.
Thanks!
Add-ons for Google Sheets, Docs, and Forms provide this capability.

How to make set of scripts available for all my Google Spreadsheets?

Excel supports the concept of a PERSONAL.XLS file which contains my personal scripts, which I want to be able to use on any spreadsheet/workbook that I open.
How do I do similar in Google Docs, i.e. have a set of scripts which, regardless of which Google Spreadsheet I open, will cause the onOpen event to be run and will thus add my extra menu?
You cannot do that in Google Spreadsheets. However the best practice is to
Write a standalone script with your onOpen and other functions.
Publish this as a library
Write a shell onOpen in each of the spreadsheets that you create
manually. :( This shell function will call the library's onOpen.
However, if you create a copy of a spreadsheet that has an associated script, then the copy will also have the script in it.
1) You can open your Script and from the Publish menu select "Test as add-on".
2) Now under "Configure New Test" you can select a document and then run the add-on for that doc.
Unfortunately you have to do this for each document one at a time. I would really love it if there was a way to tell a script to be available for all my spreadsheets, or at least have an easy way to install a personal add-on on a per-sheet basis just like you can install an add-on from the marketplace, kinda like a personal marketplace.
Although not recommended, You can also copy set of scripts to all other google spreadsheets programmatically using AppsScriptApi