AppsScriptPulse

The Gift of Script: Create a Shortcut in Google Drive with Google Apps Script

The following Google Apps Script is designed to create a Shortcut to an existing Google Drive folder, within another folder..

For Google Drive pros you can currently place a file in multiple folders, but Google will be removing this functionality on 30 September 2020. In March Google announced general availability of shortcuts in Google Drive, is is designed to replace the ‘file in multiple locations’ feature. For Google Apps Script developers wanting to migrate to Drive Shortcuts Phil Bainbridge provides this useful Apps Script snippet.

Source: The Gift of Script: Create a Shortcut in Google Drive

Apps Script V8: Keystore for global space – Desktop liberation

One of the challenges with V8 compared to Rhino is that you can’t be sure of the order of global variable initialization. Personally this is not an issue for me, as I avoid any such use of global space, but it is an issue for some. A nice way of dealing with global space is to use namespaces and IEF as I described in Apps Script V8: Multiple script files, classes and namespaces but another, perhaps less obvious way, is put all the variables (and even functions) you need to access from multiple functions in a keystore.

Interesting solution for storing/retrieving variables, particularly when you are using the new V8 runtime.

Source: Apps Script V8: Keystore for global space – Desktop liberation

Using Google Apps Script to capture who sends email from your delegated gmail account

Apps Script V8: Multiple script files and namespaces – Desktop liberation

Apps Script doesn’t have a module loader system. If you’re used to developing in NodeJs, you’ll also be familiar with importing and exporting to include required modules in your project. With Apps Script, you have no control over the order in which multiple script files are executed. In Legacy Apps Script, there seemed to be some kind of workaround going on so that global statements were executed in a sensible order (I don’t know the details), but in V8 this is not the case. …

My golden rules are

  • Nothing executable should be in global space
  • Don’t rely on the order that things are processed
  • Minimize the number of executable functions (1 is good)
  • Always assume your code will be reused somewhere else.

Source: Apps Script V8: Multiple script files and namespaces – Desktop liberation

Apps Script V8: spreading and destructuring – Desktop liberation

V8 adds destructuring from  JavaScript ES6. Legacy Apps Script already had destructuring of arrays added fairly recently, but v8 gives full a destructuring capabilitity. These destructuring and spreading capabilities, which at first may again seem a little like syntactic sugar, have contributed greatly to  the development of state management frameworks such as Vuex and Redux for client side apps. V8 brings some of that cleanliness to Apps Script.

Source: Apps Script V8: spreading and destructuring – Desktop liberation

JavaScript V8 Arrow functions, this and that – Desktop liberation

V8 adds the arrow function declarator from modern JavaScript. This is a handy shorthand but it’s more than just that. There are some behavioral differences too that you’ll need to understand before diving in. The old way of declaring functions still exists of course, and there will always be a need for it.

More tips and guidance from Bruce Mcpherson for developers migrating code to the Apps Script V8 runtime.

Source: JavaScript V8 Arrow functions, this and that – Desktop liberation

Apps Script V8: Maps and Sets – Desktop liberation

Sets and Maps can often be a cleaner way of storing data than using Objects or Arrays, even though at first glance they may seem a little redundant. Unlike an array, they are aware of what else is in the map or set (so you can avoid duplicates), and unlike an object, you can use anything as the key – including the item value itself

Given many Apps Script projects focus on manipulating data Bruce Mcpherson provides a useful introduction to Maps and Sets.

Source: Apps Script V8: Maps and Sets – Desktop liberation

Apps Script V8: Template literals – Desktop liberation

It’s a shorthand way of using a template into which variables are subsituted in a string. This allows for better reuse of string structures, and a few other goodies besides (like all V8 additions, it’s more than just a syntactical spruce up)

Bruce Mcpherson has a very useful post highlighting the benefits of using the new V8 runtime when working with string output

Source: Apps Script V8: Template literals – Desktop liberation

A Walk A Day Keeps The Doctor Away #GoogleAppsScript – plotting lat/long data on Google Maps

Nice little script snippet from Mariette Timmer which takes a .csv file with latitude/longitude points and plots them on a Google Map and sends the resulting image embedded in an email.

Source: A Walk A Day Keeps The Doctor Away #GoogleAppsScript

Things one can get used to for the V8 Google Apps Scripts engine

A bit of a monologue about various syntax changes and adjustments in learning and using the tool.

Great post from Adam Morris (@clssrmtechtools) aimed at Google Apps Script developers wanting to start coding with the more modern JavaScript syntax used in V8. Adam shares lots of great advice to get started and build upon.

Source: Things one can get used to for the V8 Google Apps Scripts engine