Is there a way to get (and change/remove) all Triggers from all documents in Google Script, as if I opened Script Editor -> Edit -> All your triggers
?
Update:
I added a few test triggers and tried to loop all the spreadsheet files as it is said by Pierre-Marie Richard:
function getAllSpreadsheetTriggers()
{
var files = DriveApp.getFilesByType('application/vnd.google-apps.spreadsheet'),
spreadsheets = [],
triggers = [];
while(files.hasNext())
spreadsheets.push( SpreadsheetApp.openById(files.next().getId()) );
for (var i = 0; i < spreadsheets.length; i++)
{
triggers = ScriptApp.getUserTriggers( spreadsheets[i] );
Logger.log(triggers);
}
}
But .getUserTriggers()
always return an empty array. I read this issue, the last answer is "We decided not to take action on this issue. Triggers always belong to a particular script and are not accessible to other scripts. The documentation has been clarified to make this clear."
It turns out that can't it be done?
You can get the trigger from your docs/forms/spreadsheets with the getUserTriggers(document), getUserTriggers(forms) and getUserTriggers(spreadsheet) methods, but it will return only the trigger for the specify file. So you'll need to loop on all the files if you want to modify the triggers from all your Drive's file.
Also, you can't modify trigger by code, but you can delete a trigger (deleteTrigger(Trigger) method) and create a new one (see TriggerBuilder class).
Edit: As FLighter point it, you can't get the triggers from another script that the one you're running. I should have read the documentation with more attention:
Gets all installable triggers owned by this user in the given document, for this script or add-on only. This method cannot be used to see the triggers attached to other scripts.
So, to anwser the original question, no, you can't. You can made some code for each script you've got, but it will require to be trigger manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With