2

I'm coding an application that will automatically open the launch meeting page for my next class, thus automatically joining me into the class ZOOM when it is time, but I'm not sure how I would go about doing the timings, I would need multiple triggers, at 9:00, at 10:20, at 11:40, at 1:00, and at 2:20, and not have them activate on saturdays or sundays. Any pointers?

Marios
  • 26,333
  • 8
  • 32
  • 52
LlamaButt
  • 431
  • 4
  • 15

2 Answers2

4

There are something that we call Triggers in Google Apps Script. Specifically, you will need a time based trigger.

Sample code using time based trigger:

function createTimeDrivenTriggers() {
    // Trigger every Monday at 09:00.   
    ScriptApp.newTrigger('myFunction')
        .timeBased()
        .onWeekDay(ScriptApp.WeekDay.MONDAY)
        .atHour(9)
        .create(); 
}

For more info, please see documentation

NightEye
  • 10,634
  • 2
  • 5
  • 24
  • 1
    Could I make this only activate on even or odd days of the month as opposed to days of the week? – LlamaButt Dec 22 '20 at 17:31
  • @LlamaButt, there are functions here you can use for this one. https://developers.google.com/apps-script/reference/script/clock-trigger-builder#everydaysn. At first glance, you can use `everyDays(n)`. You can combine it with other functions as well, like `at(date)` so it starts at this date, and then triggers `everyDays(2)` so it can become every odd/even days. That should work theoretically. – NightEye Dec 22 '20 at 17:35
  • 1
    Is there a way I could get some UI in there? Our school alternates between "a days" and "b days" and we have different classes on each day, is there a simple way to ask the user if it is an a day or a b day without HTML service? – LlamaButt Dec 22 '20 at 17:37
  • For that, you can create a new post since it is actually outside the scope of your original post. But what I can provide you is the documentation for dialogs https://developers.google.com/apps-script/guides/dialogs. Start from here and if you have doubts/questions, feel free to post another question. – NightEye Dec 22 '20 at 17:44
  • Hi @LlamaButt, for the mean time, kindly join https://chat.stackoverflow.com/rooms/226310/time-trigger so I can provide support and guide you properly. – NightEye Dec 22 '20 at 17:59
-2

https://developers.google.com/google-ads/scripts/docs/features/dates This should be the page you are looking for, I am not familiar with google apps, but it does look similar to php.

I would make a function that gets called depending on what time of day it is using the DATE methods on that website.

hope this helps! Happy coding

Jake
  • 17
  • 5
  • no, because this does not trigger the function. This would be useful for having the code recognize which class it's supposed to go to, but is useless for the actual calling of the function. And I already am familiar with date objects in javascript. Sorry. – LlamaButt Dec 22 '20 at 15:38
  • Oh I see, well maybe you can figure out how many times a day 30 minutes passes into an array then make a game loop that gets called every 30 minutes. Inside the game loop you have your time parameters for your classes depending on the time of day. For instance 9am would be (30 minutes x 18). You could do it this way, without having to access the built in date functions. Seems like outside the box thinking/cheating ;) but hopefully someone knows specifically the google apps script so they can help you more than me. – Jake Dec 22 '20 at 16:10
  • 2
    No. The function does not activate without a manual execution or external trigger, you are not understanding the problem. I need a trigger that will activate the function, not code for the function. – LlamaButt Dec 22 '20 at 16:25