Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I trigger a Google Script when a file is saved to Google Drive?

I have a VBA script which converts an Excel file to a PDF then saves it to a Google drive folder via Google Drive desktop sync.

What I would like to do is then have a Google script trigger monitor the given folder and each time a file is saved there it runs a script to email the file. I I have the script working fine when running on a time based trigger, every 15 minutes, but would prefer a realtime solution.

So i'm after like a onChange() trigger but for Google Drive.

possible?

thanks

like image 575
MrPea Avatar asked Jul 07 '16 10:07

MrPea


People also ask

How do you trigger an onEdit in Google Sheets?

The onEdit(e) trigger runs automatically when a user changes the value of any cell in a spreadsheet.

How do I automate on Google Drive?

With our add-on "Drive Toolbox" you can automate your Google Drive™ storage. Copy, move, delete or mark Google Drive™ files according to your filter criteria. Rename files within a folder or convert them to another Office format. Share files or automatically revoke shares.


1 Answers

This should be possible with the Push Notifications API of Google Drive. See this link for details.

Push Notifications

This document describes how to use push notifications that inform your application when a resource changes.

Overview

The Drive API provides push notifications that let you watch for changes to resources. You can use this feature to improve the performance of your application. It allows you to eliminate the extra network and compute costs involved with polling resources to determine if they have changed. Whenever a watched resource changes, the Drive API notifies your application. To use push notifications, you need to do two things:

  • Set up your receiving URL, or "Webhook" callback receiver.
  • This is an HTTPS server that handles the API notification messages that are triggered when a resource changes.
  • Set up a notification channel for each resource endpoint you want to watch.
    A channel specifies routing information for notification messages. As part of the channel setup, you identify the specific URL where you want to receive notifications. Whenever a channel's resource changes, the Drive API sends a notification message as a POST request to that URL.

Currently, the Drive API supports notifications for changes to the Files and Changes resources.

like image 178
Amit Agarwal Avatar answered Sep 17 '22 00:09

Amit Agarwal