简体   繁体   中英

How to automatically run a google-app-script in my case? Is setting a trigger is enough?

I have a script that loads the (File name, URL, created and last modified) into my sheet (Links tab). I used that tab to lookup all the corresponding URLs to the other 4 tabs(North,South,East,West) specifically in column F. My question is how can the script automatically run instantly so that the 'Links' tab is updated without triggering manually the 'run' button. The function of my script is to load all the data information in this drive . All I want to the 'Links' tab is to be updated instantly whenever I uploaded an image to the said drive.

Here's the script I'm currently running:

//GLOBAL VARIABLES

var ss = SpreadsheetApp.getActiveSpreadsheet()
    .getSheets()[0];
var listCell = 'B1';
var idRange = 'A2:B2';
var idCell = 'B2';


function list() {

    var arr, files, file, data, sheet;

    arr = [["FILE NAME", "URL", "CREATED", "LAST MODIFIED"]];
    files = DriveApp.getFolderById("0B-2cWUKgEfm9RVpaTkJFQU9zZzA")
        .getFiles()
    while (files.hasNext()) {
        file = files.next();
        arr.push([file.getName(), file.getUrl(), file.getDateCreated(), file.getLastUpdated(), ]);
    }
    SpreadsheetApp.getActive()
        .getSheetByName('Links').getRange(1, 1, arr.length, arr[0].length)
        .setValues(arr)
}

Google Drive doesn't allow (for the moment) to set triggers for Drive events (like uploading, deleting or editing files).

But you can set a Time-driven Trigger for your function with 1 minute period (the highest frequency) in Script Editor by pressing the button Current project's triggers .

Your problem could be partially solved if you have G Suite account. With G Suite you are able to upload files via Google Forms. And in that case you are able to add a Trigger for Form submit event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM