Articles

Set A Web Based Google Doc With Join & Google Apps Script

 

I frequently use both the mobile and web based Google Docs for work but I prefer the web based.  I use my previously created mobile only setter method to set the Daily Doc but did not have a method to set it from within the web interface.  With that, I created a web based Google Doc setter with Join and Google Apps Script.  It’s reliable and saves me time in the field.

 

Google Docs

Web vs. Mobile Based




A web based Google Doc has many pros and cons versus the mobile version.  The web version is more user friendly with a familiar user interface.  Also, it contains the full set of features such as menus, add-ons, and formatting.  While Google Docs is great on it’s own, it lacks a feature that mobile devices easily handle; mobility.  The mobile version’s forte is mobility, yet it has it’s drawbacks.  Google Docs for mobile has limited features, and only a few add-ons at the moment.  While it lacks in the above mentioned, having on-the-go access to any Doc is invaluable on the mobile version.  And because Google Docs syncs between the mobile and web, I utilize both together.

Work Site Report

I take advantage of both web and mobile Google Docs while at work.  I’ve stated before that I write a work site daily report using Google Docs.  While I use both, I prefer the web version for speed.  Because it is faster, I begin on my Surface Pro 3 laptop copying the previous day’s report.  Throughout the day, I update from my mobile device or laptop depending on time constraints and other tasks.  Transitioning between the two throughout my day makes my job easier.  However, some days work gets too busy and I must depend on the mobile version.  Hence, I’m thankful both are available.  Even after establishing my daily report on the web, I still have one problem; retrieving it on my mobile device.  I already have a solution for setting and getting the daily report however the setter method is exclusively for mobile devices.  Therefore I created a setter method to join the web and mobile Google Docs versions.

Automation Tools

Join

The appropriately named application “Join” brings devices together.  Join is available on Android, Chrome, and Windows 10 devices.  Join allows access and control on other devices from remote locations.  Most noteworthy is the developer, Joao Dias.  While he stays busy with his AutoApps, he still makes time for support requests.  I highly suggest looking into this application.  And among all great features, Join has Tasker integration.  Now, using Join, Tasker users have an event context and a list of actions.  Additionally, my favorite feature is the restful API.  It’s a simple HTTP URL with parameters such as title, text, icon, device ID, priority etc that integrates with Join’s Tasker event context.  Because of the API, Join extends further to other devices and services.

Google Apps Script

The second automation Tool is Google Apps Script (GAS).  It can integrate and automate google’s apps and services. See my previous article on the subject.  It uses a simple programming language, javascript on Google’s servers.  Although automating Google’s services is great, there are methods to integrate 3rd party services.  That method is the “URL Fetch Service”.  The service issues HTTP requests and receives responses.  Furthermore a typical use for this service is for RESTful API’s.  Therefore Join’s API is a perfect candidate.

Bringing Them Together

Join API

Join’s API integrates with Tasker beautifully using the Send Push parameters.  It’s a simple and effective URL schema with optional parameters.  Additionally, Joao Dias created a tutorial page explaining it.  From his website, I created a Send Push API URL using only the device ID and text parameters.  The device ID parameter is what Join uses to identify a particular device.  And, the text parameter is how Join integrates with Tasker.  The integration is a Join event context in Tasker.  The event context uses the familiar AutoApps command system; [parameter]=:=[command].  My particular Join API Send Push URL push resembles the following: “setFieldEngineersDailyReport=:=[fileID]”.  The string on the left of the separator (=:=) is the event parameter.  And the string on the right is reserved for the specific Google Docs’ file ID.  As a result, the final URL schema matches the following:

https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?text=setFieldEngineersDailyReport=:=[fileID]&deviceId=[deviceID]

GAS Libraries, URL Fetch, & UI

With the URL Fetch Service, sending Join API calls are possible.  I created a bound script and added a top-level menu and submenu containing my devices with the UI method.  The top-level menu is titled “AKM Scripts” and submenu is “Set Daily Report on Device” with “Nexus 6p” and “Nexus 6”.  Next I wrote a short library script which returns the Join device IDs by passing the device name.  The device names accepted in the library are the same as the  devices listed in the submenu.  Because this is necessary for the end result, the next section of code changes sharing permissions to “ANYONE_WITH_LINK”.  And the last code section is a second custom library.  This library’s function takes arguments “fileID” and “deviceID”.  The fileID is of the Google Doc and the device ID is the above mentioned Join device ID.  Finally, passing those arguments requests a specific URL response using the URL Fetch Service.  As a result, the URL response triggers a Tasker event in the form of the AutoApps-type command.

AutoApps Command System in Tasker

The Join API incorporates nicely into Tasker via the AutoApps Command System (ACS).  Created by Joao Dias long ago, the ACS is how his apps communicate and pass variables between each other through Tasker.  The “Join Received Push” Tasker event context reacts to the “text” parameter in the Join API Send Push URL.  For my specific example, the text parameter is the following:

“setFieldEngineersDailyReport=:=[fileID]”

In my Tasker profile, the Google Document’s file ID is a local variable in the task.  The remaining actions append the date with an equal sign, “=”, and set it to a global variable for later use:

“[fileID]=[Date]”

Now with the global variable set on my mobile device, other tasks call it to fetch the specific Google Doc.

Set A Web Based Google Doc With Join and Google Apps Script

From A PC




Starting from the Google Drive homescreen, I only take a few steps to set a specific Google Doc on my mobile device.  Because the GAS is bound to each document, copying the previous day’s Doc also copies the GAS script.  Once loaded, selecting the drop down menu opens a submenu listing devices.  Selecting a device executes the script.  After giving permission through authorization, a UI alert notifies that the script is complete.  Finally, it reads:

“Daily Work Site Report Set! Check for notification on device”

On A Mobile Device

On a mobile device, visual feedback signals that the task executed as planned.  The visual feedback uses a snackbar from the Snackbar Tasker Plugin.  And it states:

“Document ID Shared! You can now open this document when you’re at the work site”

In order for this GAS to be practical, I use the same getter methods described here.

Final Thoughts

Creating this web based Google Doc setter broadened my Javascript knowledge.  It also saves me time and effort while at work.  Because I created libraries, the code in each Doc is light and easily modifiable.  Furthermore, libraries make my code future-proof.  It’s the perfect solution and works every time.  As long as you have access to Google Apps Script, sending information from any Google Drive app to Tasker is simple.  What other ways can you integrate a web based Google Doc with Tasker to create some practical automation?

What did you think???