Get permissions automatically for Google Apps Script when Sheets copied - google-apps-script

I have programmed a script in a Google Sheet to treat the data stored in this script. This script runs automatically based on time.
I use a Google Sheet per month, so I make a copy of this Sheet with its programmed script every month. I modify the date and rename the file.
Nervertheless when I make the copy, it's necessary to get permissions in Google Apps Script to run the script. I would like to program a script that makes the copy, rename the file, changes the date and gets permission automatically. Making copy, renaming and changing date are easy, but I don't know how get permission automatically. Is it possible? Anyone can help me?

Related

What is the best way to create Container-bound Scripts that can be cloned?

According to Google Apps Script, container-bound scripts https://developers.google.com/apps-script/guides/bound is limited to that file.
I wrote a script that reads some values of GSheet and submits it to the server.
But I also want this spreadsheet to be cloned for different usages. But each time I clone this spreadsheet, it creates a new container-bound script and it asks for permissions again.
Is there a way to clone the spreadsheet and have it run the script without asking for permissions again?

Running a basic script on a Google sheet without authorising

I have a font and alignment script which works like a charm on our daily spreadsheet. However I copy the blank file (template) 30 ish times for each month. As soon as I have done this, the font script stops working unless I go in and authorise it for each new sheet. Is there any way, maybe with the script library i can run it automatically and not have to authorise each new sheet? All users have edit access to the sheet. I have been reading and playing with the script library but can't seem to get it to work at all.
Thank you for any help.
The simplest way to authorize a script and then not need to reauthorize a derivative of it, is to not create a derivative of it. Currently, you indicate the workflow is create a copy of yesterday's document, and then everyone works on the copy.
If you reverse the order, such that you archive the copy, then you will no longer need to continually reauthorize your script in a new file, as the working file contains an authorized Apps Script project.
Create a template file, which has the corresponding sheets you would like to start each day with
Write a script which will perform 2 tasks
Export the current state of the active workbook to a new workbook (or even a PDF or other archive-ready asset)
Replace the contents of the active workbook with those from the template workbook.
Run this script either manually or from a time-based trigger.

Creating trigger in google script to save file to drive

I'm trying to modify this script so that once a day it runs exporting the result to my drive and overwriting the file that is there. I'm completely new to google scripts so this might be a very basic request. To clarify, i know how to set a tim trigger. I'm looking for how i edit the script so that it writes then overwrites the file to my drive on the timetrigger

How do I copy a script from one spreadsheet to another spreadsheet?

I need to copy an existing script, which I did not write, into my existing spreadsheet. The script is called "SaveBack", and can be found here: https://docs.google.com/a/levelgroup.com/spreadsheet/ccc?key=0Agcb8bUVVOOodHhoV3BrRGZ6UEdSYnVLSEk3bllxRnc#gid=1.
My existing spreadsheet is too complex (it has many other spreadsheets that link to it) to copy all of its sheets into the spreadsheet that contains the script. I have already copied the SaveBack editor sheet template sheet to my main spreadsheet, but I can't figure out how to copy the SaveBack script that goes along with it into my spreadsheet.
Can anyone help? Thanks!
Open the save back script, select the script text, copy it, go to your sheet, create a new script (blank template), paste the script you copied into your new script, name is SaveBack (assuming it's a project), check the triggers on the original script and make sure your triggers match, and you should be good to go. You will have to change any sheet, document, or other string ID's to match your files' Id's, but that isn't too bad.
I do this sort of thing all of the time when I'm migrating things back and forth between my work and personal account. You could also create a copy of the other person's spreadsheet that you linked above, and it will move the script over with it. Then you can go to the script and get the project key to use it as library in your own scripts. Since you're using your copy as the library, you don't have to worry about someone else changing the script and breaking your functionality.

I need a script to monitor a specific Google Drive folder whenever there is a change and notify me by email

I have been trying all day and I found this:
http://www.jellybend.com/2012/12/19/monitor-google-drive-folders-with-google-apps-script/
The attached script worked only partially for me. It doesn't respond to change to the subfolders even there are files inside the subfolders (eg. rename/delete the subfolder). It also seems to have errors if I delete and re-add the same file to the folder again, it just doesn't email me for the newly added "old file".
I also found this:
https://developers.google.com/drive/v2/reference/changes/list#examples
but unfortunately I am not really sure what those parameters are and I am just inexperienced in writing something like that.
Any help will be greatly appreciated! Thanks!
The file monitoring code at that link, is an Apps Script bound to a Sheet. An Apps Script can be bound to a Sheet, Doc, Form or Site. An Apps Script can also be a stand alone application. So, any code you may want to write, does not need to be in a spreadsheet.
An Apps Script can be set up to have a Time-driven event trigger.
There is also a Script Service to build Clock Triggers.
ClockTriggerBuilder Class
Using Time Driven Event Trigger, or a Clock Trigger you could use the getSize() method to return the amount of disk space used by the item:
Class - Folder - getSize Method
// This example logs the first file's size in bytes
// Note: This can also be used on a folder to get the size of its contents
var file = DocsList.getAllFiles[0];
Logger.log(file.getSize());
Of course, you would need to know what the original size of the folder or file was, and so you would need to store the current size somewhere. You could create a file for storing that information, or use the built in database that Apps Script has.
For storing your historical folder or file information you could use ScriptDB.
ScriptDB
Quote:
ScriptDB is a JavaScript object database for Google Apps Script. Each script project gets a database, which the script can use to save, update, and search JavaScript object data.
You could write historical file and folder info to a spreadsheet or document also.
Depending on who owns the file, and who is accessing the file, permissions would need to be granted, or you'd need to use oAuth2 to authenticate who has access to the file and folder information.
If you can't write all the code yourself, you could set up a shared Apps Script file, or find some other way to have people collaborate on the project.
I've been researching this on my own for some time and came up with a script bound to a spreadsheet as well. Hope it can help someone, as it seems that a lot of people are looking for something similar. My script is monitoring a folder and sends notification to all the current viewers of the folder as soon as there is new file added. Trigger to run the script could be set depending on the needs of the user. In my case hourly worked just fine.
Spread Sheet with the script: https://docs.google.com/spreadsheets/d/1CzVADjUTT2d9Y5OGDOnv37mCaO49kPt4RmnyZgzjTKA/edit#gid=0
If you would like to try this script just make sure you are logged in with your google account when you open the link and you should be able to make a copy of the spreadsheet.
This Google Script will send an email notification to you or other email addresses when a file in a Google Drive folder has been added, renamed, changed, or modified. http://baumbach.com/google-script-2/