With google apps script how can I know in a function if it's called by user or trigered?

Viewed 30

I create a function "myFunction" in a google spreadsheet which could be called by user or run by Time-driven trigger. I want to display a message if it's user runs the function or log a message if it's the running by trigger.

At the moment I create this "myFunction" with a parameter (userCall as boolean) and create two others functions :

function createHistoUser() {
  createHisto(true);
};

function createHistoTrigger() {
  createHisto(false);
};

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Custom Menu')
    .addItem('Create Histo', 'createHistoUser')
    .addToUi();
};

It's not very clean I think. If there is a method to know if it's a user calling or a triggered calling I can delete the 2 functions. Thanks for your help.

0 Answers
Related