1

In Google Apps Script, is there any way to check if any users besides myself are currently editing a sheet? I don't really need to know much about those users — just knowing whether anyone else has the sheet open in a browser window would suffice.

My goal is to automatically re-sort a sheet every hour or so, but only if no other users are connected to the sheet, so as to avoid interfering with their work. I can't seem to find any information on how to programatically access the list of currently connected users, though.

Thanks in advance!

Fran

fparedes
  • 11
  • 1
  • You could use the Drive API to check if the last modification was from yourself / your service account. https://developers.google.com/drive/api/v2/reference/files See also https://stackoverflow.com/questions/51336254/determining-active-users-on-the-same-google-spreadsheet – tehhowch Dec 14 '18 at 16:01
  • 1
    Possible duplicate of [Getting a list of active file viewers with apps script](https://stackoverflow.com/questions/39602639/getting-a-list-of-active-file-viewers-with-apps-script) – tehhowch Dec 14 '18 at 16:02

1 Answers1

1

Add this script to your script editor. Every time a cell on any sheet is edited it will popup a small message stating user email for 2 seconds:

function onEdit(e) {
    var user = Session.getEffectiveUser().getEmail();
    SpreadsheetApp.getActiveSpreadsheet().toast('User working: '+user, 'Info', 2);
}
Sam Tyurenkov
  • 430
  • 4
  • 19