5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GoogleAppScript setIntervalを使う

Last updated at Posted at 2016-03-10

GoogleAppScriptでsetInterval的なことをやる方法について記載

ScriptApp.newTriggerで関数呼び出しの定義ができます。
以下は1分ごとにスプレッドシート上にダイアログを表示する例

function createTrigger() {
  ScriptApp.newTrigger('showMsg')
      .timeBased()
      .everyMinutes(1)  //毎分
      .create();   //トリガー
}

function showMsg(){
  Browser.inputBox("trigger!")
}

トリがーを止める場合は、以下のようにdeleteTrigger()にtriggerIdを指定して止める必要があります

function deleteTrigger(triggerId) {
  // Loop over all triggers.
  var allTriggers = ScriptApp.getProjectTriggers();
  for (var i = 0; i < allTriggers.length; i++) {
    // If the current trigger is the correct one, delete it.
    if (allTriggers[i].getUniqueId() == triggerId) {
      ScriptApp.deleteTrigger(allTriggers[i]);
      break;
    }
  }
}

以下は、すべてのtriggerを止めるサンプル

function deleteTriggerAll() {
  var allTriggers = ScriptApp.getScriptTriggers();
  for(var i=0; i < allTriggers.length; i++) {
      ScriptApp.deleteTrigger(allTriggers[i]);
  }
}

もしくは、「アカウント情報」の接続しているアプリの一覧から削除することで止めることができます。

1.Google drive右上のユーザーのアイコンをクリック

2.「アカウント」ボタンをクリック

3.「接続済みのアプリとサイト」から「アプリを管理」をクリック

4.不要なGoogle APP Scriptを選択

5.「削除」ボタンをクリックすると止まります

以上

参考
https://developers.google.com/apps-script/guides/triggers/installable#errors_in_triggers

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?