Skip to content

Instantly share code, notes, and snippets.

View ttsukagoshi's full-sized avatar

TSUKAGOSHI Taro ttsukagoshi

View GitHub Profile
@ttsukagoshi
ttsukagoshi / RemindMyGoogleCalendar.js
Last active April 17, 2023 00:19
Remind myself of the events scheduled tomorrow in my Google Calendar. The notification will come to my Gmail.
const DRY_RUN = false;
function getEventsForTomorrow() {
const timeZone = Session.getScriptTimeZone();
let tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1); // get date for tomorrow
const tomorrowStr = Utilities.formatDate(tomorrow, timeZone, 'yyyy-MM-dd');
// Get the events
const calendars = CalendarApp.getAllCalendars(); // get all calendars that the user owns or is subscribed to
@ttsukagoshi
ttsukagoshi / Calendar2Sheets.js
Last active March 9, 2023 00:46
Googleカレンダーに登録した予定のうち、指定期間内で特定のキーワードを持つイベントを抽出して、Googleスプレッドシートの新しいシートに一覧表として落とし込む簡易ツール。Googleスプレッドシートにバインドされたスクリプトとして利用。
const SHEET_NAME_CONFIG = 'config';
/**
* スプレッドシートが開いたときのメニュー追加
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('カレンダーから転記')
.addItem('カレンダーからイベント取得', 'getFilteredCalendarEvents')
.addToUi();
@ttsukagoshi
ttsukagoshi / ListWithQuota.js
Last active January 17, 2023 00:12
Googleフォームで、選択肢ごとに定員を設定して、定員に達したらその選択肢を非表示にするためのGoogle Apps Script。 https://gist.github.com/ttsukagoshi/d9fad5b8865066ddefa64be9cff208d0 の後継。
const SHEET_NAME_CONFIG = '01_設定'; // 設定シート名
/**
* onFormSubmitを手動でも実行できるように、スプレッドシートにメニューとして設定
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('定員付き選択肢')
.addItem('選択肢設定(手動)', 'onFormSubmit')
.addToUi();
@ttsukagoshi
ttsukagoshi / yearsLater.js
Created September 1, 2022 09:13
5年後の年度末を自動的に計算して置換するための、Google Docs-boundのGoogle Apps Script。スクリプトを実行すると、特定の文字列(ここでは `<<年>>` )を、所定の年度末の年に置き換える。
const YEARS_AFTER = 5; // 5年後
function onOpen() {
DocumentApp.getUi()
.createMenu('期限入力')
.addItem('年挿入', 'enterYear')
.addToUi();
}
function enterYear() {
@ttsukagoshi
ttsukagoshi / convert2Hyperlink.js
Last active May 13, 2022 06:39
Googleスプレッドシートで、選択したセル範囲の文字列をテキストリンクに変換するためのGoogle Apps Script(GAS)。使用したいスプレッドシートのメニュー>拡張機能>Apps Scriptからエディタを表示して、convert2hyperlink.jsの内容をコピペ&保存する。保存後、スプレッドシートを再読み込みすると、メニューに「URL変換」という項目が追加されているので、選択、実行。
@ttsukagoshi
ttsukagoshi / checkUnreadGmail.js
Last active July 29, 2022 00:05
Gmailの受信トレイにある未読メールの件数をGoogleチャットで通知する、Spreadsheet-boundのGoogle Apps Script。
/**
* Gmailの受信トレイにある未読メールの件数をGoogleチャットで通知する、Spreadsheet-boundのGoogle Apps Script。
* 前提:
* スプレッドシートに以下のように2列が設定されていること:
* | ACCOUNT | WEBHOOK_URL |
* | -------------------- | --------------------------- |
* | my-account@gmail.com | (Googleチャットのwebhook URL) |
* スクリプトは、実行しているアカウントとmy-account@gmail.comが一致すれば、
* その受信トレイにある未読メールの件数をWebhookを設定したチャットに投稿する。
* my-account@gmail.comは当該チャットに参加している必要がある。
@ttsukagoshi
ttsukagoshi / getRawEmail.js
Created April 14, 2021 14:23
Parse the string of recipients returned by Gmail into raw email addresses. For example, if Gmail provides a recipient string in form of `George Washington <gwashington@potus.com>`, this function will return `gwashington@potus.com`
/**
* Parse the string of recipients returned by Gmail into raw email addresses.
* For example, if Gmail provides a recipient string in form of
* "George Washington <gwashington@potus.com>"
* this function will return
* "gwashington@potus.com"
* @param {string} gmailRecipients String of comma-separated recipients returned by GmailMessages.getTo(), .getCc(), or .getBcc()
* @returns The raw email addresses of gmailRecipients, without recipient name and angle brackets
*/
function getRawEmail_(gmailRecipients) {
@ttsukagoshi
ttsukagoshi / onOfficeHours.js
Last active March 4, 2021 10:01
This gist is no longer maintained. It has moved to a GitHub repository => https://github.com/ttsukagoshi/on-office-hours
// 実行するGoogleアカウントのカレンダーに登録されている「日本の祝日」カレンダーのIDを参照する↓
const CAL_ID_HOLIDAY_JA = 'en.japanese#holiday@group.v.calendar.google.com';
// オフィスアワーの開始・終了時刻をHHmmss形式のstringで設定↓
const OFFICE_HOURS = { start: '090000', end: '170000' };
// エラーとなったときの再実行までの時間(ミリ秒)↓
const RETRY_MILLISEC = 5 * 60 * 1000;
// officeHourCheckがエラーとなったときの再実行までの時間(ミリ秒)↓
const RETRY_MILLISEC_OFFICE_HOUR_CHECK = 5 * 1000;
const TIMEZONE = Session.getScriptTimeZone();
const UP_KEY_DATE = 'upDate';
@ttsukagoshi
ttsukagoshi / departments-of-akita-local-gov.js
Last active February 22, 2021 01:17
秋田県庁の部署一覧( https://www.pref.akita.lg.jp/pages/genre/organization )をGoogleスプレッドシートに落とし込むためのGoogle Apps Script
/* global SpreadsheetApp, UrlFetchApp */
/* exported fetchAkitaDeps */
const TARGET_URL = 'https://www.pref.akita.lg.jp/pages/genre/organization'; // クロールするサイトのURL
const SHEET_NAME = 'List'; // データを挿入するシート名
const INSERT_DATA_POS = { row: 4, col: 1 }; // データの挿入開始位置
const INSERT_EDIT_TIME_POS = { row: 1, col: 4 }; // 最終更新日時の挿入位置
const REGEXP_DEPT = RegExp('<h3 class\=\"c-category-panel-item__heading\"><a href\=\"(?<deptUrl>[^\"]+)\">(?<deptName>[^の]+)の関連ジャンル<\/a><\/h3>[ ]*?<ul class\=\"c-category-panel-item__body c-gallery-list c-gallery-list--2\">(?<sectSource>.*?)<\/ul>', 'g'); // 部局名、URLを検出
const REGEXP_SECT = RegExp('<li class\=\"c-gallery-list__item\"><a href=\"(?<sectUrl>[^\"]+)\">(?<sectName>.*?)<\/a><\/li>', 'g'); // 課名、URLを検出
@ttsukagoshi
ttsukagoshi / choice-editor-for-google-form.js
Created November 18, 2020 03:46
A Google Apps Script sample for a simple solution to manage the choices in list or multiple-choice items of a specific Google Form using Google Sheets.
const CONFIG = {
'sheetName': 'Choices', // Name of sheet
'cellFormUrl': { 'rowNum': 4, 'colNum': 2 }, // Row and column numbers of the cell that designates the URL of Google Form.
'rangeOffsetChoices': { 'rowNum': 6, 'colNum': 3 }, // Left- and upper-most cell of the range in which choices are listed.
'timestampItemTitle': '最終更新日時' // Title of the item in the target Google Form that denotes the timestamp of which the form was last updated.
};
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Choice Editor')