Google Apps Script

Google Apps Script(GAS、ガス[2])とは、Googleによって開発されたスクリプトプラットフォームである軽量のアプリケーション開発のためのGoogleのワークスペースプラットフォーム。 主にGoogleのサービスを自動化するスクリプト言語である。JavaScriptがもとになっているため汎用性が高く、開発環境はGoogle Chromeだけでいいのでプログラミング初心者が始めやすい言語の1つである。Google Apps Scriptは当初、Mike HarmがGoogleスプレッドシートの開発者として働いていたときに、サイドプロジェクトとして開発された[3]。Google Apps Scriptは、2009年5月に、GoogleドキュメントのプロダクトマネージャーであったJonathanRochelleによってベータテストプログラムが発表されたときに初めて公開された[4]。 その後、2009年8月にGoogle AppsScriptがすべてのGoogleAppsPremierおよびEducationEditionのお客様に利用可能になる[5]。 これはJavaScript1.6に基づいているが、1.7と1.8の一部、およびECMAScript 5APIのサブセットも含まれている [6]

Google Apps Script
開発元 Google
プラットフォーム InstagramYouTubeGmailカレンダーChatドライブドキュメントスプレッドシートプレゼンテーションKeepサイト、Vault
種別 マクロ言語およびクラウドコンピューティング
公式サイト 公式ウェブサイト
影響を受けた言語 JavaScript
Apps Script
開発元 Google
初版 2009年8月19日 (2009-08-19)[1]
プログラミング
言語
JavaScript
種別 Web application framework, scripting framework
公式サイト script.google.com

2020年3月、Googleは従来の Rhino JavaScript インタープリタに加えて V8 Rhino JavaScript インタープリタの提供を開始し、ECMAScript6以降の機能にも対応した[7]

Apps Scriptプロジェクトは、 Googleのインフラストラクチャで、サーバー側で実行される。 Googleによると、Apps Scriptは、「Google製品とサードパーティサービス全体のタスクを自動化する簡単な方法を提供します」[8]。 Apps Scriptは、 Googleドキュメント、スプレッドシート、スライドのアドオンを強化するツールでもある[9]

概要

Googleスプレッドシートで主に使われるが、それ以外でも利用ができる。非常に適応範囲が広いので、例えば、SNSに返信が届いた場合Gmailに届ける、Gmailで期限の近いタスクを自分のSlackで表示する等のこともできる。

function doGet(e) {  
  var searchTerm = 'Script Tools'
  var ui = XmlService.createDocument(XmlService.createElement('html')).setDocType(XmlService.createDocType('html'))
  var body = XmlService.createElement('body')  
  body = buildTree(body, searchTerm);
  ui.getRootElement().addContent(body)
  return HtmlService.createHtmlOutput(XmlService.getRawFormat().format(ui))
}


function buildTree(node, searchTerm) {
  var ul = XmlService.createElement('ul').addContent(XmlService.createElement('p').addContent(XmlService.createText(searchTerm))); 
  // Use of the Apps Script DriveApp Service to retrieve the collections.  
  var folders = DriveApp.getFoldersByName(searchTerm).next().getFolders()
  while (folders.hasNext()){    
    var thisFolder = folders.next();   
    var li = XmlService.createElement('li');   
    var resp = buildTree(li, thisFolder.getName())            
    ul.addContent(li);
  }

  var files =  DriveApp.getFoldersByName(searchTerm).next().getFiles()   
  while (files.hasNext()) {    
    var thisFile = files.next()    
    if (thisFile.getMimeType() === "application/vnd.google-apps.document") {
      urlBase = "https://docs.google.com/document/edit?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.document";
    }    
    else if (thisFile.getMimeType() === "application/vnd.google-apps.spreadsheet") {      
      urlBase = "https://spreadsheets.google.com/ccc?key=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.spreadsheet";
    }
    else if (thisFile.getMimeType() === "application/vnd.google-apps.script") {      
      urlBase = "https://docs.google.com/fileview?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.script";
    }
    else if (thisFile.getMimeType() === "application/vnd.google-apps.presentation") {       
      urlBase = "https://docs.google.com/present/edit?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.presentation";
    }
    else if (thisFile.getMimeType() === "application/vnd.google-apps.drawing") {       
      urlBase = "https://docs.google.com/drawings/edit?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.drawing";       
    }
    else {
      urlBase = "https://docs.google.com/fileview?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/application/vnd.google-apps.unknown";    
    }    
    
    var li = XmlService.createElement('li');     
    var image = XmlService.createElement('img').setAttribute('src', iconHTML);    
    var fileLabel =  XmlService.createElement('a').setAttribute('href', urlBase + thisFile.getId())
                      .setAttribute('target', '_blank').addContent(XmlService.createText(thisFile.getName()))
    var fileLabelPanel = XmlService.createElement('div').setAttribute('style', 'display:flex;flex-direction: row;')
    fileLabelPanel.addContent(image)
    fileLabelPanel.addContent(fileLabel)    
    li.addContent(fileLabelPanel)
    ul.addContent(li)
  }    
  node.addContent(ul)
  return node;   
}

アドオン

2014年3月、Googleはドキュメントとスプレッドシートへのアドオンを導入。まもなくフォームにも導入された。アドオンを使用することで、メールマージやワークフロー、ダイアグラムビルダーをドキュメントエディタに追加することが可能になった。このアドオンらは全てApps Scriptで構築されているか、あるいはそれを使用してUIを表示し、タスクを外部バックエンドに依存させることで形成されている。例えばメールチンプは、メールチンプのプラットフォームと通信し、メールを送信するためのドキュメント用アドオンを使用している。

これが登場する前は、スクリプトギャラリーというものが存在し、そこでスクリプトを公開することができた。これを通じインストールすると、Apps Scriptのコードのコピーが自身のスプレッドシートに入るようになっていた。アドオンでは、エンドユーザーにソースコードを公開することはされず、全員が最新バージョンを使用することができる。

アドオンリリースの一環として、開発者がエディタに統合しやすくなるよう、ガイドとCSSを導入している[10]。また、それぞれのアドオンは正式公開前にGoogleによってレビューされるので、Google社員からのアドバイスを受けることができる。広告をアドオンに掲載することは原則不可能だが、マネタイズで利益を得ることは可能とされる[11]

関連項目

参考文献

  1. Meyer, David (2009年8月20日). “Google Apps Script gets green light”. CNet. http://news.cnet.com/8301-1001_3-10314002-92.html 2011年3月26日閲覧。
  2. Google Apps Script(GAS)を解説!初心者でも分かる使い方とは”. MarkeTRUNK. 2023年6月1日閲覧。
  3. Koleda (2019年8月21日). Celebrating 10 years of Apps Script: looking back on how it started”. Google Cloud Blog. 2019年8月22日閲覧。
  4. Rochelle (2009年5月27日). Old tool, new tricks”. Google Cloud Blog. 2019年8月22日閲覧。
  5. Levey (2009年8月19日). Google Apps Script Launched to Google Apps Premier and Education”. Google Apps Script. 2019年8月22日閲覧。
  6. Kienle, Holger (May–June 2010). “It's About Time to Take JavaScript (More) Seriously”. IEEE Software 27 (3): 60–62. doi:10.1109/MS.2010.76. http://www.computer.org/portal/web/csdl/doi/10.1109/MS.2010.76 2011年3月25日閲覧。.
  7. Alexandrina Garcia-Verdin (2020年3月17日). Data processing just got easier with Apps Script’s new V8 runtime”. Google Cloud Blog. 2021年7月4日閲覧。
  8. Google Apps Script
  9. Bring a little something extra to Docs and Sheets with add-ons
  10. エディタ アドオンの UI スタイルガイド”. Google Developers (2022年8月17日). 2022年11月6日閲覧。
  11. I've started a little experiment...”. Google (2014年9月21日). 2014年12月24日時点のオリジナルよりアーカイブ。2022年11月6日閲覧。

外部リンク

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.