# Scripts, scripts, scripts!

**URL:** <https://community.glideapps.com/t/scripts-scripts-scripts/18965>\
**Category:** Ask for Help\
**Created:** [November 26, 2020, 6:15pm UTC](https://community.glideapps.com/t/scripts-scripts-scripts/18965 "2020-11-26T18:15:21Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [November 26, 2020, 6:29pm UTC](https://community.glideapps.com/t/scripts-scripts-scripts/18965/5 "2020-11-26T18:29:05Z")

</div>

Here is an example I use for creating time-based triggers. It accepts 3 parameters:

1. `func` - the name of the function to be executed
2. `unit` - either ‘hours’ or ‘minutes’
3. `interval` - how often to run it (based on the unit)

So for example, calling it as `create_time_based_trigger('clear_old_data', 'hours', 6)` would create a trigger that calls the function `clear_old_data` once every 6 hours.

```
function create_time_based_trigger(func, unit, interval) {
  var ss = SpreadsheetApp.getActive();
  switch (unit) {
    case 'minutes':
      ScriptApp.newTrigger(func)
      .timeBased()
      .everyMinutes(interval)
      .create();
      break;
    case 'hours':
      ScriptApp.newTrigger(func)
      .timeBased()
      .everyHours(interval)
      .create();
      break;
  }
}
```

---

_[View the full topic](https://community.glideapps.com/t/scripts-scripts-scripts/18965)._
