4

I would like to run this script (embed drive list in a site) that I have used but only set the trigger to run it during office hours Monday - Friday.

I would like the script to run every 5 minutes but stop over night and at weekend. So I figured that I need to:

  1. Have a script that programatically creates a trigger to run the actual function during the day and give that a trigger to run once at the beginning of each day.

  2. Have a second script to delete the days trigger run once at the end of the day.

I am doing this as I have just learned that there is a maximum amount of CPU time you can use during a day so I do not want to waste it during times I don't need the list updated.

I can see how to create a trigger but it is not clear how to create a trigger to activate another script (function).

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Chris Lee
  • 43
  • 1
  • 3

1 Answers1

8

I think it would be quite easier to insert a small routine at the beginning of your main function that checks the time of the day and simply 'returns' when out of office hours. This way you can let your trigger set to 5 minutes all the time. This 'hour check' will be very short in terms of processing time.

here is a test function to show how it works :

function officeHours() {
    var nowH=new Date().getHours();
    var nowD=new Date().getDay();
    // Logger.log('day : '+nowD+'   Hours : '+nowH)
    if (nowH>17||nowH<8||nowD==6||nowD==0) { return }

   Browser.msgBox('time to work !');//normally your real function should begin here...
}
Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107
Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • Awesome thanks that way when it is out of hours the script only takes a second or two and not using too much of the daily alotted time. – Chris Lee Jun 12 '12 at 12:01