Created
January 27, 2016 05:46
-
-
Save s2kw/a4e827cc5cc27fa65faf to your computer and use it in GitHub Desktop.
昔書いたGoogle SpreadSheet用のスクリプト。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
カレンダーにリマインダーの理論間隔でイベントを設置するスクリプト | |
ver. 0.1 2012/1/3: SASAKAWA Kunihiro | |
ver. 0.2 2012/1/4: SASAKAWA Kunihiro : コメントを書き直し。 | |
*/ | |
/* | |
makeCalEvent | |
カレンダーにイベントを書き込む関数 | |
cal as Calendar Object | |
カレンダーオブジェクト。何度も取得するのもアレなので一度取得したら保持させるようにしたので引数で渡してます。 | |
グローバル変数にしとけよって話だ…。 | |
GoogleAppってグローバル変数ってつかえるのかね | |
eventName as String. | |
カレンダーに記述するイベント名を文字列で取得。 | |
targetDate as Date | |
実際に記述する日時を日付で指定。 | |
count as Integer | |
リマインドした回数を詳細とかイベント名に記述する。 | |
descript as String | |
カレンダーのイベントの詳細部分に記述する文字列。 | |
*/ | |
function makeCalEvent(cal,eventName, targetDate,count,descript){ | |
var cname = eventName; | |
if (cname != "" & cname != "cancel"){ | |
targetDate.setHours(12); | |
targetDate.setMinutes(0); | |
targetDate.setSeconds(0); | |
// Browser.msgBox(descript); | |
cal.createEvent( | |
eventName+"@"+count+"回目", | |
targetDate, | |
targetDate, | |
{ | |
description:count + "回目のリマインド\r\n\r\n" + descript, | |
sendInvites:false | |
} | |
); | |
} | |
} | |
/* | |
改行テスト | |
*/ | |
function kaigyou(){ | |
// Browser.msgBox("kaigyou1 \r\n end1"); | |
// Browser.msgBox("kaigyou2 \n end1"); | |
// Browser.msgBox("kaigyou3 \r end1"); | |
var cal = CalendarApp.openByName("記憶強化リマインダ"); //←リマインダー専用のカレンダーを予め作成。名前は任意で。 | |
var day = new Date; | |
makeCalEvent(cal,"kaigyou1",day,1,"kaigyou1 \r\n end1"); | |
day.setTime(day.getTime() + 24*3600*1000); | |
makeCalEvent(cal,"kaigyou2",day,1,"kaigyou2 \n end2"); | |
day.setTime(day.getTime() + 24*3600*1000); | |
makeCalEvent(cal,"kaigyou3",day,1,"kaigyou3 \r end3"); | |
Browser.msgBox("end"); | |
} | |
/* | |
メインの関数な。スプレッドシートから呼び出すのはこれ。 | |
makeRemindEventOnCal カレンダーにリマインダーイベントをセットするスクリプト。 | |
リマインドの間隔は以下のURLの記事を元に作成してます。 | |
http://readingmonkey.blog45.fc2.com/blog-entry-556.html | |
*/ | |
function makeRemindEventOnCal(){ | |
var cal = CalendarApp.openByName("記憶強化リマインダ"); //←リマインダー専用のカレンダーを予め作成。名前は任意で。 | |
//カレンダーに表示するイベント名を入力する。 | |
var eventName = Browser.inputBox("イベント名を入力してください","カレンダーの見出しで表示されます。",null); | |
if(!eventName)return; | |
//リマインドする回数を入力。 | |
var count = Browser.inputBox("安定期後にリマインドしたい回数を数値で入力", "整数でよろしく", null); | |
var description = Browser.inputBox("詳細を記述してください。","未記入でもOK",null); | |
var remindArray = [1,2,4,7,15,21]; | |
//軌道に乗るまでの1ヶ月はこの間隔で広げて行く。 | |
var remindMonth = 31; | |
//軌道にのったら一月以上あけてはならないらしい。 | |
var beforStationaryPhaseCount = remindArray.length; | |
for(var i = 0; i < beforStationaryPhaseCount; i++){ | |
var day = new Date; | |
var target = remindArray.shift(); | |
day.setTime(day.getTime() + target*24*3600*1000);//指定の日にリマインドタイミングをセット。 | |
makeCalEvent(cal,eventName,day,i+1,description); | |
} | |
var afterDay = new Date; | |
if(count != 0){ | |
for(var i = 0; i < count; i++ ){ | |
afterDay.setTime(afterDay.getTime() + remindMonth*24*3600*1000);//31日後にセット。 | |
makeCalEvent(cal,eventName,afterDay,i + beforStationaryPhaseCount +1,description); | |
} | |
} | |
//完了通知 | |
Browser.msgBox("イベントのセットが完了しました。"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment