AppsScriptPulse

Bulk convert Google Sheets to PDFs using Google Apps Script

Bulk convert Google Sheets within a given Google Drive folder into PDFs and optionally delete the original file.

Bulk convert Google Sheets to PDFs using Apps Script

Bulk convert Google Sheets to PDFs using Apps Script

Features

  • Maximum runtime – in order to prevent the tool from reaching the limits imposed by Google you can adjust the number of minutes the tool can run for. Change this in the ‘GlobalVariables.gs’ file in the Script Editor.
  • Continue from where it left off – if you have a lot of Google Sheets to convert and the above runtime is reached the tool will save its progress and prompt you to run it again, avoiding any file duplication.
  • HTML popup – as well as the ‘Log’ sheet the tool displays a direct popup to the user if it encounters a problem.
  • PDF counter – after successfully running the tool will include the number of PDFs created as part of the success popup to the user.

Source: The Gift of Script: Bulk convert Google Sheets to PDFs

Workaround: Checking Existence of File ID in Google Drive without Access token and API key using Google Apps Script

This is a workaround for checking the existence of file ID in Google Drive without both the access token and API key.

When you want to check whether the file of the file ID is existing in Google Drive, generally, you might use Drive API and Drive service (DriveApp) of Google Apps Script. In this case, the scope of Drive API is required to be used. By this, the access token and the API key (in the case of publicly shared files) are required to be used. But, there might be a case that the available scopes are limited. In this post, I would like to introduce a workaround for checking the existence of file ID in Google Drive without both the access token and API key.

This workaround could have been a nice addition to a recent project I was working on to audit a bunch of Google Drive file IDs. As noted in this post a big benefit of the approach is there is no need to include Google Drive authentication scopes to your project. See the source post for the code and explanation.

Source: Workaround: Checking Existence of File ID in Google Drive without Access token and API key

Import CSV data into Google Sheet using Google Apps Script

Loop through CSV files in Google Drive and extract their contents into specific areas in Google Sheet files.

CSV File template to copy data into

CSV File template to copy data into

The following Google Apps Script is designed to loop through a folder of CSV files in Google Drive, extract the data, create a Google Sheet file per CSV, and insert the data into specific rows/columns.

Source: The Gift of Script: Import CSV data into Google Sheet files

Efficient file management using batch requests with Google Apps Script 

Google Drive alone can handle small file management jobs, but for larger batches of files, it can be too much for a simple Drive script to manage. With Google Apps Script, even large batches can be executed within 6 minutes, offering businesses the monetary and time benefits of efficient file management. This report looks at how Google Apps Script improves file management with batch requests, judging its efficacy by measuring the benchmark.

We’ve regularly highlighted work from Kanshi Tanaike in Pulse and it’s nice to see it also being highlighted in the official Google Cloud Blog. I’m sure many Google Workspace developers, like me, have encountered issues with managing large volumes of Google Drive files. In the post Kanshi Tanaike highlights how batch methods can be used to greatly speed up the process when interacting with the Google Drive API.

Source: Efficient File Management using Batch Requests with Google Apps Script | Google Cloud Blog

Search Google Drive for ‘Shared with me’ with Google Apps Script

Search Google Drive for all of the files found in the Shared with me space and collate the results into a Google Sheet.

Search Google Drive 'Shared with me' and collate the results

Search Google Drive ‘Shared with me’ and collate the results

It will collate the following information into a Google Sheet:

  • The file name as a direct clickable link,
  • The file ID,
  • The type of file eg PDF, Google Sheet/Doc,
  • The file creation date,
  • The file last updated date,
  • The folder path,
  • The file owner.

Source: The Gift of Script: Search Google Drive for Shared with me

Rose Photo Manager – Bulk copy Google Photos to Google Drive

Rose Photo Manager - Bulk copy Google Photos to Google Drive

If you, like me, miss the automatic sync between Google Drive and Google Photos we lost in July 2019 (as Google thought we’d find it too complicated!) this is the GSheet for you. Rose Photo Manager copies the photos and videos from Google Photos and stores them onto your GDrive

This blog post describes how to set the supplied script to regularly copy your Google Photos from Google Drive (just like how it used to be done!). It builds on this post, but adds a load more features, one being keeping the photos in a GDrive folder with the same name as GPhoto albums that they belong to.

Source: Rose Photo Manager – Bulk Copy Google Photos to Google Drive

SuperFetch Plugins: Apps Script streaming with Tank and Drive (Copying very large files to/from Google Drive with Apps Script)

Tank and Drv are SuperFetch plugins to emulate streaming and use the Drive REST API with Apps Script … This article will cover how to copy very large files using Tank to stream and Drv to upload and download partial content. The Apps Script Drive services have a limit on the size of files you can write, and very large memory usage can potentially cause Apps Script to fall over mysteriously

Clever stuff as always from Bruce Mcpherson, this time looking at how you can handle large files with Google Apps Script. We’ve featured some of Bruce’s other SuperFetch posts on Pulse, but developers can benefit from exploring the entire series so far on Bruce’s website. As well as SuperFetch plugins for Firebase and Twitter I’m personally interested in the evolution of the Google Drive client (Drv).

Source: SuperFetch Plugins: Apps Script streaming with Tank and Drive – Desktop Liberation

Programmatically manage and apply Drive Labels using new API functionality

Many of our customers already take advantage of the Drive Labels capabilities to classify content and implement policies on their Drive files for governance and Data Loss Prevention.

Today, we’re happy to announce a highly requested update that will enable you to programmatically manage labels at scale via Drive APIs.

Google Workspace devs might be interested in this update to the Drive Labels API which enables additional functionality. As noted in the source post:

The new Drive Labels API supports reading Drive Label taxonomies. New functionality in the Drive API can be used to apply labels, set fields on files, and find files by label metadata. As a whole, these new API features enable numerous use cases including, bulk-classification, Apps Script driven workflows, third-party integrations, and other organizing and finding needs.

The post includes links to a number of useful resources including reference documentation.

Source: Programmatically manage and apply Drive Labels using new API functionality

Automatically backup Google Drive folders to Cloud Storage with Google Apps Script

Image credit: Stéphane Giron

Few days ago, with the launch of French region ‘europe-west9’ in GCP, I made an apps script to backup a Drive folder to Cloud Storage. It is a cool script and works nicely but after some exchange, we can make it better.

So here I come back with onleebackup an open source code to backup multiple Google Drive folders to cloud storage with synchronisation.

A very interesting open source project from Stéphane Giron which lets you backup Google Drive folders to Google Cloud Storage. An important caveat is with Google Apps Script limitations like script runtime and URL Fetch POST size this won’t work if you have gigabytes of data. The code has some nice features like handling Google Docs/Sheets/Slides file types, converting them to equivalent MS Office formats as well as management of Google Drive shortcuts, which requires calls to v3 of the Google Drive API. The source post provides details for setting up onleebackup, which also includes a link to a previous post with code highlights.

Source: Automatically backup Google Drive folders to Cloud Storage

Working with the Google Drive API Revisions history: Tips for handling revision merges with Google Apps Script

Having spent quite a bit of time working with the Google Drive API Revisions resource in this post I thought it would be useful to share some of the lessons and solutions I’ve picked up along the way. For this I’ll be sharing code snippets for interacting with the Revisions resource with Google Apps Script, but the solutions discussed could easily be applied to your programming language of choice.

Source: Working with the Google Drive API Revisions history: Tips for handling revision merges