Showdow
Showdow

Reputation: 11

Check which sheets are currently being viewed in your spreadsheet

to explain the issue briefly, there are certain sheets in the spreadsheet that are supposed to be hidden constantly.Though they have to be opened sometimes to change some data on them. The issue is that there are multiple collaborators on the spreadsheet getting annoyed by people leaving these sheets open and not hiding them again after they're done.

I have a lot of stuff on the sheet automatized through a minutely cycle anyhow so my first approach was to just hide them every cycle if they've been left open. The problem there is that the hideSheet() figuratively slaps the sheet out of your hand even if you're actively viewing it which shouldn't be happening.

I know that there are functions like getActiveSheet() and after some testing I've seen that this function, if you run it for yourself, returns the sheet you're currently viewing (like I myself am viewing).

My idea to overcome the problem that the hideSheet() function also closes the sheet you're currently viewing was to check whether the sheet is currently active for someone on the spreadsheet.The "myself" case obviously works here as I can just check whether I am viewing the sheet as a case for hiding it or not.

Long story short, does anyone have an idea how I can get a list of sheets that are currently being viewed or like being open on other peoples' ends?

Or if that's not possible to answer, does anyone know how I can ensure that the sheets are being rehidden on a regular basis without having the problem that I might just throw someone out of the sheet while he still has it open?

Upvotes: 1

Views: 170

Answers (1)

Wicket
Wicket

Reputation: 38150

Try the change installable trigger.

An installable change trigger runs when a user modifies the structure of a spreadsheet itself—for example, by adding a new sheet or removing a column.

It might be triggered by showing/hiding a sheet. If so, your script could log when a sheet was shown then do something with that like polling the active sheet when the edits / change the spreadsheet and if the active sheet is not the same, then hide the sheet that was shown.

Reference

Upvotes: 1

Related Questions