0

I have a script that runs on a Google Docs spreadsheet and works fine. I need to automate the running of this script and have used a trigger, which also works fine. In the options for triggers, I can run the script at 10 to 11 or 11 to 12, but not 10:30.

I can use the exact time option, but that means resetting the date each time. I could also run it at 10am and put a sleep command in, but not sure if there is a time restriction on how long a script should run for: this would effectively run for 30 mins.

Any other thoughts please?

Thanks Ade

Mogsdad
  • 44,709
  • 21
  • 151
  • 275

2 Answers2

4

Setting the trigger by script seems to give more options than the UI, see the ClockTriggerBuilder https://developers.google.com/apps-script/class_clocktriggerbuilder

eg

ScriptApp.newTrigger("myTimeTrigger")
  .timeBased()
  .onWeekDay(ScriptApp.WeekDay.MONDAY)
  .atHour(12).nearMinute(15)
  .create();
DavidF
  • 1,335
  • 1
  • 15
  • 26
  • Hi, thanks for the reply. I am unsure where to actually put this code. – user1554409 Jul 27 '12 at 13:23
  • I have changed that to the following: ScriptApp.newTrigger("myTimeTrigger") .timeBased() .everyDays(1) .atHour(10).nearMinute(35) .create(); But do I add it to the start of the script or create a new function for it? Normally I can work these things out but I need a higher view to get me going :) Thanks David – user1554409 Jul 27 '12 at 13:34
  • I have not done this but it seems to me that you need a 'first time through execution' eg "if no triggers add this one then exit" at the start of your script. – DavidF Jul 28 '12 at 22:28
0

You could set a trigger every 30 minutes and check in the script itself 'what time is it ?' not 10:30 ? then return... depending on the accuracy you need to get it can be tricky to give it a good start... so you could do the same on a minute trigger... (forget the sleep option, it should be more than total acceptable run time) See also this post that was quite similar: Working hours only trigger

Community
  • 1
  • 1
Serge insas
  • 45,904
  • 7
  • 105
  • 131