AppsScriptPulse

Create Responsive Emails Easily with Google Apps Script and MJML

Today I had the task of implementing a newsletter for internal updates and decided to use Google Apps Script since I was already using it for managing the project data. Based upon past experiences with emails using HTML I need this area was full of landmines and I didn’t want to navigate through it. 💣

So I decided to use MJML with Google Apps Script.

Sending emails using Google Apps Script is a common task, however, creating HTML emails that render consistently across different email clients and that look visually appealing can be challenging.

Justin Poehnelt’s post on DEV Community, “Using MJML in Google Apps Script to Send Beautiful Emails,” offers a solution to this problem. MJML is a markup language that makes it easy to create responsive HTML emails. It removes some of the complexities of HTML email development, allowing users to focus on the content of their emails.

In the post, Justin explains how to use MJML with Google Apps Script to send beautiful, responsive emails. He also mentions that he has published a library, MJMLApp, that “hides the gnarly bits” of using MJML with Google Apps Script. This library is available on GitHub in the mjml-apps-script repo where you can find the library ID and basic usage information.

Source: Using MJML in Google Apps Script to Send Beautiful Emails

‘AI Agents’ in Google Apps Script: Automate Google Workspace with Natural Language

Imagine that you write in plain English what you want to do in Google Workspace (eg. workflows) and it happens just like magic. Insert text prompt, Gemini will generate the code for you and run it immediately. A dream? No, reality, thanks to my conceptual and practical idea of how to implement AI Agents in Google Apps Scripts to leverage the V8 runtime.

Ivan Kutil has explored the concept of AI Agents in Google Apps Script, enabling Google Workspace automation via plain English descriptions. Users describe their automation needs in natural language, which is then processed by Gemini API to generate the necessary code. The generated code is then executed in your Google Apps Script project.

Ivan’s solution uses the gemini-2.0-flash-thinking-exp-01-21 model, an experimental model within Vertex AI specifically designed to reveal its ‘thinking process’, resulting in more reliable code generation. The enhanced reasoning capabilities of this model are particularly beneficial for complex automation tasks, making it a powerful tool for Google Workspace customisation.

To ensure that the agent is doing the right thing, the clever bit is you can test the execution via a dry-run, where the code created with Gemini Flash Thinking is sent to an internal ‘Tester’ agent, which uses Gemini to comment on the code and summarises it in a log. It’s important to review the script before running it, as Ivan accepts no responsibility for the results of the script. Another nice feature is the generated code is stored in the Cache, so after running a dry-run and then a run, the same version will be executed within the Cache limit (currently set to 5 minutes).

This solution, which mirrors Gemini for Workspace’s ability to generate and execute basic Python code, suggests a future where Gemini for Workspace could write and execute Apps Script code for basic tasks. This has the potential to transform how users interact with and automate their Google Workspace environments.

If you are interested in a version of Ivan’s solution that incorporates my GeminiApp library, follow this link. For additional information on Ivan’s solution including setup instructions follow the source link.

Source: Create AI agents in Google Apps Script with Vertex AI and Gemini

How Apps Script Became the Ultimate LLM Fine-Tuning Tool

If you have domain-specific knowledge that you want an LLM to leverage, you probably have a use case for fine-tuning. Fine-tuning can significantly improve how well the model understands and responds to your queries, whether it’s legal documents, medical texts, financial reports, or niche industry data.

The most crucial step in this process is structuring your data correctly. If your dataset is well-organized and formatted properly, the rest of the workflow becomes much more manageable. From there, it’s just a matter of setting up a few configurations and automating parts of the process with Apps Script. That’s where things get interesting and surprisingly efficient.

Source: How Apps Script Became the Ultimate LLM Fine-Tuning Tool

Streamline Your Google Sheets: Automate Row Archival with Google Apps Script

Archive Google Sheet Data with Google Sheets API Advanced Service in Google Apps Script

Keeping your Google Sheets organised can be a chore. A recent tutorial by Scott Donald shows you how to automatically archive old rows based on multi-column parameters using Google Apps Script and the Advanced Sheets API, making data management easier and more efficient. This post highlights Scott’s approach to scripting a solution, including how to set up the Sheets API, the main components of the script, and potential applications.

As always Scott packs in a lot of useful tips and guidance; in particular, the tutorial highlights how to archive data using just five API calls, potentially making it faster than the standard SpreadsheetApp approach. Scott also details how to modify the script to suit different processes and includes details on his SsReq class. It provides a structured way to perform common operations like retrieving data, finding rows based on criteria, copying rows, appending rows, and removing rows, making it a great addition to your personal Apps Script toolbox.

For detailed explanations, code examples, and helpful tips, consult the complete tutorial.

Source: Creating a Google Sheets Row Archiver with Google Sheets API Advanced Service and Apps Script – Yagisanatode

Bulk Image Generation with Imagen 3, Sheets, and Apps Script

Discover how to combine Imagen 3 and Google Sheets for rapid image creation. Automate your workflow and generate visuals in bulk.

Have you ever wished you could create a bunch of images without the hassle of typing in each prompt one by one? Well, Stéphane Giron has shared a clever solution using Google’s Imagen 3, Google Sheets, and Apps Script to streamline this process. While Gemini for Workspace is rolling out to more users and includes Imagen 3 for image creation in apps like Slides and the Gemini side panel, it doesn’t offer an easy way to create images in bulk. That’s where this method comes in. Instead of making images one at a time, this approach allows you to generate multiple images at once, saving you time and effort.

To get started with this method, you’ll need a Google Cloud Project and creating a service account (see the Build an AI slides reviewer with Gemini tutorial for instructions on setting this up). Once that’s set up, you create a Google Sheet with a column for your text prompts, and another for the links to the generated images. The images are automatically saved into a specific folder in your Google Drive.

The real magic happens with Apps Script. It uses Vertex AI to connect with the Imagen 3 model. The script reads each prompt from your sheet, sends it to Imagen 3 to create an image, and then stores the image in Google Drive. It also helpfully adds the image’s link back into the Google Sheet.

Check out the source post for the required code and instructions.

Source: Imagen 3 + Google Sheets + Google Apps Script: The secret to effortless bulk image generation

Unlocking Google Docs Content: A comprehensive guide to text extraction with Google Apps Script

4 Approaches to extracting the body text of a Google Doc with Google Apps Script. Full Code and tutorial

Scott Donald must be one of the most comprehensive Google Apps Script writers I know. All of his tutorials are packed with information and useful tips. This recent post is no exception, as Scott dives in and shares this detailed guide on retrieving a Google Docs body text using Google Apps Script.

The tutorial explores four approaches to extracting text from a Google Doc:

  1. DocumentApp: This approach is straightforward for basic text extraction but may not capture all elements, especially “Smart Chips.”
  2. DocumentApp with Element Iteration: This method allows for extracting text and URLs from standard text and supports some “Smart Chips” like Date, Rich Link, and Person.
  3. OCR Approach: This involves converting the document to a PDF, applying OCR, and reading the extracted text. It captures most displayed text but may not recognise emojis or some formula symbols.
  4. Docs API Advanced Service: This approach utilises the Docs REST API to access text, links, and specific “Smart Chip” data. It offers more control over data extraction but may require navigating complex JSON responses.

Scott’s tutorial provides a comprehensive and practical guide to retrieving Google Docs body text using Google Apps Script. Be sure to check out the full tutorial for detailed explanations, code examples, and helpful tips. And don’t forget to share your preferred approach and any challenges you’ve encountered on Scott’s post.

Source: Get a Google Docs Body Text with Apps Script – Yagisanatode

Google Apps Scripts for Google Workspace Administrators from The Awesome Script Site

Discover a treasure trove of scripts at The Awesome Script Site. Developed primarily for Google Workspace, these scripts offer solutions to common challenges faced by businesses and organizations. Created by Jonas Lund and soon other contributors, these scripts are free to use and come with comprehensive documentation. Share this resource with your network and remember to visit often for new additions.

The Awesome Script Site, by Jonas Lund, is a “treasure trove of scripts” for both users and Google Workspace administrators. The administrator scripts simplify various administrative tasks, but you will require a Google Workspace admin role to use them. Due to their handling of sensitive user data obviously please take time to review the scripts to make sure you are happy with how they work.

The scripts cover a wide range of functions, including:

  • Alias Management: Manage user email aliases directly from a Google Sheet.
  • Chromebook Reporting: Fetch and organize Chromebook data from your Google Workspace.
  • Group Member Management and Reporting: Bulk add or remove group members and generate group member reports.
  • OU Management: Create, list, and delete Organizational Units (OUs) based on specific criteria.

It’s worth spending a little time exploring the Awesome Scripts site to discover these admin scripts and more. To keep up-to-date on new ‘Awesome Scripts’ you can follow Jonas Lund on LinkedIn. Follow the source link to get the scripts and read more.

Source: The Awesome Script Site

Going beyond the menu: Programmatic controlling Google Sheets protection using Google Apps Script

Google Apps Script automates tasks like managing protections in Google Spreadsheets. These protections control user access to specific cells. While scripts exist for this purpose, users still encounter challenges, prompting this report. The report aims to introduce techniques for managing protections using sample scripts, helping users understand and implement this functionality.

Google Sheets aficionados are likely no strangers to the “Protect sheet” and “Protect range” options tucked away in the menus. These features offer a basic level of control over who can edit what within your spreadsheet. But what if you need more dynamic, automated control over these protections? That’s where the power of Google Apps Script and the Sheets API comes into play.

This post from Kanshi Tanaike provides a deep dive into how you can programmatically manage protections in your Google Sheets. While the traditional menu options are great for static scenarios, using Google Apps Script allows you to create more flexible and powerful protection workflows.

Why Go Script?

  • Dynamic Protections: Instead of manually adjusting protections, you can use scripts to change them based on specific conditions or events within your spreadsheet.
  • Automation: Integrate protection changes into larger automation workflows, streamlining processes and reducing manual intervention.
  • Granular Control: Achieve a level of control over cell-level permissions that goes beyond the standard menu options.

Some possible use cases for developers could include:

  • Approvals Automation: Imagine a scenario where certain parts of a spreadsheet need to be locked down once a manager approves them. With this solution, you could create a script that automatically protects those ranges upon approval.
  • Time-Limited Editing: Need to open up a section of a spreadsheet for editing only during a specific window of time? You could use Google Apps Script to handle this, automatically protecting

The scripts provided by Kanshi Tanaike offer a starting point for exploring these possibilities.

Source: Technique for Protecting Google Spreadsheet using Google Apps Script

Google Apps Script: Mastering version control and deployment with CI/CD

Automate publication of your script from development to production easier.

This post by Stéphane Giron provides a CI/CD solution for Google Apps Script, which makes it easy for you to automate the deployment of Apps Script code from a development version to production. The solution uses the Apps Script API to manage versions and streamline the code copying process.

Stéphane has previously created a backup solution for Google Apps Script code, but it lacked version control and multi-file support. This new CI/CD solution addresses these limitations by using the Apps Script API to handle version management and the publication process.

The post includes the necessary code and configuration for implementing this solution. To use this solution you will need to enable the Apps Script API and as well as setting up your project with a standard Google Cloud Platform (GCP) Project.

As a bonus the solution also allows you the option of restoring previous versions of your deployed script, providing a rollback mechanism in case of errors or issues. This solution is lighter weight than other CI/CD setups featured in Pulse, but is easier to set up, providing a practical approach to implementing CI/CD for Google Apps Script projects and enhancing code management and deployment processes.

Source: Quick and not so dirty CI/CD solution for Google Apps Script | by Stéphane Giron | Oct, 2024 | Medium

Enhance your Google Docs skills with these Google Docs API snippets for Google Apps Script

Google Apps Script offers Document service for basic document tasks and Google Docs API for advanced control, requiring more technical expertise. This report bridges the gap with sample scripts to unlock the API’s potential.

Kanshi Tanaike’s latest blog post, “Unlocking Power: Leverage the Google Docs API Beyond Apps Script’s Document Service,” is a great read for Google Workspace developers. It offers a goldmine of code snippets that will supercharge your Google Docs projects. Tanaike highlights the advantages of using the Google Docs API for more advanced features and flexibility compared to the standard Apps Script DocumentApp Service. Even though the API requires a bit more technical know-how, Tanaike provides clear, practical examples to get you started.

Some of the sample snippets include:

  • Changing page orientation (portrait to landscape and vice versa)
  • Merging table cells
  • Creating and managing footnotes
  • Highlighting superscript numbers in footnotes
  • Resetting borders and shading
  • Creating checkbox bullets
  • Changing section margins
  • Controlling table row overflow
  • Setting custom line and paragraph spacing
  • Replacing placeholders spanning multiple paragraphs
  • Converting between soft and hard line breaks
  • Managing table borders
  • Creating nested lists
  • Retrieving all URLs from a document

Kanshi Tanaike’s post serves as a valuable resource for developers looking to expand their Google Docs capabilities. Hopefully with these sample scripts, you can start unlocking new levels of automation and customization in your Google Doc projects.

To delve deeper into the world of Google Docs API, follow the source link post.

Source: Unlocking Power: Leverage the Google Docs API Beyond Apps Script’s Document Service