Unable to delete triggers (google-apps-script)

2019-02-14 16:29发布

问题:

I appear to have triggers that I cannot delete in my Google Apps Script. I have a theory as to WHY I cannot delete them, but no clue how to fix the problem. These triggers were attached to a script bound to files on a separate Google account that were shared with me. I of course was able to edit and modify the script and such as I wanted while the files were shared. Since then though the Google account that was sharing the files with me was deleted and I think the triggers that are "frozen" are residues from those files from that account. Any suggestions on how to fix this issue?

回答1:

Simple triggers can not be deleted from that window: See Here

Instead add this function to your script and run it:

function deleteTriggers() {
  var allTriggers = ScriptApp.getProjectTriggers();
  for (var i = 0; i < allTriggers.length; i++) {
    ScriptApp.deleteTrigger(allTriggers[i]);
  }
}


回答2:

Have you tried going to your Google account, then choosing "Account Settings" and then "Account permissions". You should be directed to a list that has every permission (apps and scripts). You may be able to find it there.

https://security.google.com/settings/security/permissions?pli=1



回答3:

You could try to find out more about the script's container document. You can check for edit URLs and for users. If the document was not bound to a container, you could access the sharing information from the menu. If you are the last person to use the script, you could also copy the script and delete the original script - manually or as a document. But take care of any dependencies like script properties.

I wrote a short loop to log information about container Url and its viewers:

function containerFinder() {
  if (DocumentApp.getActiveDocument()) { 
    var document = DocumentApp.getActiveDocument();
    var editUrl = document.getUrl();
    var editors = document.getViewers();
    Logger.log("This Script belongs to a document.");
    Logger.log("Edit Url: " + editUrl);
    Logger.log("Editors: " + editors);
  }
  else if (SpreadsheetApp.getActiveSpreadsheet()){
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    var editUrl = spreadsheet.getUrl();
    var editors = spreadsheet.getEditors();
    Logger.log("This Script belongs to a spreadsheet.");
    Logger.log("Edit Url: " + editUrl);
    Logger.log("Editors: " + editors);
  }
  else if (FormApp.getActiveForm()){
    var form = FormApp.getActiveForm();
    var editUrl = form.getEditUrl();
    var editors = form.getEditors();
    Logger.log("This Script belongs to a form.");
    Logger.log("Edit Url: " + editUrl);
    Logger.log("Editors: " + editors);
  }
  else {
    Logger.log("This Script does not seem to belong to any container.");
  }
}