Co-Pilot can't see which triggers a project has, so it happily adds a second nightly trigger next to the first, or edits a function without knowing a form-submit trigger calls it. triggerInventoryForPrompt() returns a plain-text list of the project's installed triggers: handler function, event type and source, ready to paste into a brief.
When to use
- Before asking Co-Pilot to change, rename or add any triggered function
- Inheriting a script and wanting to know what runs on its own
- Spotting duplicate triggers after a few rounds of “run setup again”
How to use this snippet
/**
* Plain-text list of this project's installed triggers for a Co-Pilot brief.
* Only lists triggers the current user owns in this project (that's all Apps Script exposes).
*
* @return {string}
*/
function triggerInventoryForPrompt() {
var triggers = ScriptApp.getProjectTriggers();
var lines = ['Installed triggers in this project (' + triggers.length + '):'];
if (!triggers.length) lines.push('- (none)');
triggers.forEach(function (t) {
var source = String(t.getTriggerSource());
var sourceId = '';
try { sourceId = t.getTriggerSourceId() || ''; } catch (e) {}
lines.push('- ' + t.getHandlerFunction() + ': ' + String(t.getEventType()) +
' (source: ' + source + (sourceId ? ' ' + sourceId : '') + ')');
});
lines.push('');
lines.push('Simple triggers (onOpen, onEdit, doGet, doPost) are not listed: they run by name. ' +
'Do not add a duplicate of any trigger above, and tell me before renaming a handler.');
return lines.join('\n');
}
Example
function logTriggersForBrief() {
console.log(triggerInventoryForPrompt());
}
// Installed triggers in this project (3):
// - nightlySync: CLOCK (source: CLOCK)
// - onFormSubmitHandler: ON_FORM_SUBMIT (source: SPREADSHEETS 1AbC...)
// - onDealsEdit: ON_EDIT (source: SPREADSHEETS 1AbC...)
Tips:
ScriptApp.getProjectTriggers()only returns triggers you own in this project. A teammate's triggers won't appear; ask them to run it too.- The same handler listed twice for the same event usually means a duplicate. See delete-triggers-by-handler.
- Time-driven triggers don't expose their schedule through the API, so add “runs nightly around 2am” to the brief yourself.
Tip: paste the Log into your NitroGAS Co-Pilot brief, next to your header map and Script Property names, before asking for changes to triggered code.
Happy Coding!
