About Metric Rat

Facilities Manager by trade, working at an independent school for children with special needs (autism & learning difficulties). Enjoys classic cars (1962 MG Midget owner), running an L322 Range Rover (and also an Audi cab 3.0 and MX5, whilst constantly reparting my daughters Ford Ka) and fiddling with computers (which generally means fixing everyone elses problems with Windows, whilst I sail along happily on Xubuntu Linux :) ). Play guitar, bass and ukelele for fun, and when time allows do a spot of sailing and keep active in the garden. My blog is in essence an echo of my daily trials and tribulations and triumphs :)

GAS Folders, Sub Folders and their Files

Google Drive is a wonderful thing, but when it comes to getting at a file with scripts things can get a little quirky. Every file and folder has a unique ID number (28 digits, letters and other marks) which can make it easy to locate it, if you know how. However you can of course have many files, or folders with the same name spread out across your Google Drive, which can create a bit of a problem when trying to find the file or folder. Very often you may have to iterate over “all the folders” in order to find what you want, using names to do this can be problematic.

I find I am routinely needing to grab a list of filenames, file IDs, or file types, and routinely searching the web each time I need to do this, therefore it was about time I tied down the required scripts in one place for reuse. The scripts I have put together will request either a folder name or ID in order to iterate over the files within that folder and return the results to a spreadsheet. The scripts can be used as a base, and edited to suit specific requirements by adding further properties to return, or through the use of if statements to narrow down selected files.

  • You can find the ID of the folder by looking in the url address bar if you have the folder open in Google Drive
  • You can also right click on the folder and then Shareable Link
  • Finding the name should be obvious! – use search in Google Drive to check for folders with the same name. It may be wise to do this occasionally if you use name a lot in your scripts, and to make your folder names unique

In my scripts I have chosen to return the filename, the mime type, the file ID, and to create a download link. I also include a helper script (courtesy of Sandy Good) that presents the mimetype in a more user friendly way. All four folder scripts rely on this. Thanks should also go to Brian P and AD:AM on the google group support forum for their code.

I will add a link to a google sheet which contains all the scripts, just make a copy of it to your own google drive, authorise the scripts and away you go.

Continue reading

GAS Import CSV from GMail Attachment

I have a weekly email sent to me with a csv attachment. This needs to be opened and the contents pasted into a google sheet, the data therein is then used for a variety of other applications running on Google sheets. Fortunately there is a way to automate this and to parse the csv to sheets. I have robbed and amended the code provided by Digital Inspiration to do this. The linked page also includes other examples of scraping csv data from an email attachment. The key to getting this to work is a consistent approach by my email sender, who needs to use the same email address and subject in order that the GMail filter I set up can assign a label to the email. The script is run from the receiving google sheet on a timed trigger, once a week.

The sheet needed sorting to meet requirements of others. Above code kept nice and short thanks to the parsing API provided by Google. Of course, this will work for a single user google account, calling on the gmail of that user. Because I have G Suite it is simple to create a separate account to handle this type of thing.

 

GAS – Three Crackers: 1. Insert image at specific place in a table, 2. Remove extra paragraphs created by 1, 3. Proportionally size your image

The code, used on a google sheet to add an image to a specific location in a google doc table, should be self explanatory! I use this when an image is needed in a spreadsheet data to google doc to pdf creation exercise (hmmm – had better post that up too 😉 Continue reading

AppInventor – Create Dynamic First List for Listpicker

Following on from my recent post on Dynamic Lists for Listpickers, I ventured a bit further.

Well I now have a rough version (and it is ugly!) that creates a dynamic list for the first list in a nested listpicker. This assumes a list of names or words in the master list, and that these are sorted alphabetically. The issue with creating such a thing is that, say for names, there are 26 letters that names could start with, but that the distribution of names is very uneven. In my sample list 3 letters took over 30% of the entire list. My aim was to present nested lists that could all be viewed without scrolling (between 10 and 12 items), but because of the above this is just not possible all the time. I only have the blocks here that create the first list for the listpicker, the A-D,E-H,etc. as the blocks probably need some optimisation before writing the whole thing out. But here goes: Continue reading

AppInventor – Post Data to Google Sheet

Thought I would write this one up on here, can’t take any credit for it, as original idea posted on youtube (credits below), but if I have it here it is easier to grab and use when I need it.

I have previously worked up a solution using a Google Form to submit data to a google sheet from an AppInventor app, but this method uses a standalone google apps script to do the same, but without the baggage of the google form. We will need to:

  • Have a google account (we want to use)
  • Create a spreadsheet, and set this out with the columns we need
  • Create a google apps script
  • Create an App Inventor app with the correct blocks

Continue reading

Google Sheets – ArrayFormula with Header/s

The array formula is a wonderful thing in Google Sheets, in most cases providing the opportunity to enter just the one formula and have it automatically fill down as new entries appear from elsewhere.

A clever trick though is to create an array within an array, which allows for header rows to be included.

Continue reading

Google Sheets – Google Apps Script – One to One Meeting Tracker

I was presented with a word document last week with a table full of names of staff and dates of their one to one meetings (who uses spreadsheets for managing this sort of thing ;)), ….”Can you make it so that an email gets sent to the supervisors when it is time for them to hold another one to one meeting with their staff?”

“Yes, of course.”

First job was to grab the data and convert it into a manageable list. Ended up with 8 columns: Name, Supervisor, Job Role, Department, Date of Meeting, Completed, Notes/Comments, date for Next Meeting. The notes were to allow for entries of reasons why the meeting could not take place, e.g. maternity leave or long term sick. There was all sorts of rubbish written in the table that wasn’t a date, people who had left and started during the year, which all had to be cleared out. Eventually got a neat set of data to play with. Continue reading