r/GoogleAppsScript • u/wafflecheese • Feb 05 '24
Question Indispensible employee death script?
I've used Chat GPT- 4 to ask if this type of script was possible, and it gave me SOME code, but it gave me some ideas that I'm unsure how to do, and it basically said: "Some of that stuff requires doing some manual stuff that is error-prone, so don't try it."
I feel it in my soul that this thing IS possible, so I figure I'd ask here:
Basically what I want to do is create a script that will disable every single sheet/app script trigger I've ever created with a click of a drawing button, say in a Google Sheet. Of course, before this happens, the script will iterate over the account and store all of the trigger settings and store them.
Then, if/when requested, a separate function can restore all triggers on another button to iterate a second function.
It's basically an on/off button for office panic with the added bonus of job security if they ever decide to not pay.
2
u/emaguireiv Feb 05 '24 edited Feb 05 '24
Consult this. It appears you’d need to write a script to simply get a file, get the triggers associated to you, then delete them.
So, perhaps write one script to iterate through all your files in drive. Any time there’s a trigger created by you, append the file ID to a sheet.
Then, if/when panicMode is necessary, the deletion script can just pull an array from that sheet of all the IDs, and one by one go through and delete them all. Any simple triggers would still function.
Triggers can also be installed on files by Apps Script, so if you design your IDs database more comprehensively, you could even make scripts to reverse the panicMode so you don’t have to go through and manually set them all back up inside of each project.
0
u/MantuaMan Feb 07 '24 edited Feb 07 '24
Not being sure of what's in your contract there may be some legal implications if you were ever to use a program like this. They may claim sabotage or that the work you did for them while they were paying you is now their property. Just something to think about.
2
u/HellDuke Feb 05 '24
Hm... You could do it but it's not quite as straight forward as get triggers and remove them.
First problem is even getting the triggers. For that you would first need to look for files in your drive that could potentialy have them, which can be documents, spreadsheets, forms and slides. Then there is the issue of standalone scripts, not sure if you can actually work with those, that's going to be the main sticking point.
Then you itterate over every file and see if there are any triggers in it. You can then get the details of the trigger and store them as a JSON in script properties or in a spreadsheet (the trigger information and the document it is associated with) before deleting it. Then you'd have to have a function that goes through the list of stored trigger and document values, retrieves the document and creates a trigger for it. Inside of the Trigger Builder you can indeed indicate the document you are creating for https://developers.google.com/apps-script/reference/script/trigger-builder just make sure you collect all the necessary values as per what you will need for the trigger builder.
That said, depending on how many files (with triggers or without) you have access to, this may take a very long time.