Clear certain cells on Window Close AppScript - google-apps-script

I wanted an appscript mechanism, where I want to clear certain cells (A2:B8) if the spreadsheet window is closed. I have one way of doing it and that is:
onOpen()
{
sheet.getRange("A2:B8").setValues("");
}
But this seems like a hack but I wanted to know if there's a definite way to do so... like for example:
Browser.onWindowClose()=>{clearCells()}

You maybe able to do this if you have a modal dialog or sidebar open. If sidebar or dialog close is attempted, you may be able to catch the event with beforeunload, if catched, clear all cells using google.script.run(). This assumes user is closing the sidebar before/along with the Google sheets main web app.

There isn't onClose() or onExit() built in trigger as of yet.
Here is the list with all the currently available triggers.
The lack of this feature has already been reported in the IssueTracker.
You can go there and click on the star button to the top left of the page to "increase" the chances for this feature to be implemented by google.
As a side note, clearContent() would be more appropriate:
sheet.getRange("A2:B8").clearContent();

Related

Google Apps Script; Sidebar OnClose

Is there a way to hook into the CLOSE event of the Ui Sidebar ?
I read up on the docs but could not find one.
Use-Case: User choices on the Sidebar updates the spreadsheet visually like coloring cells for easy visual responses. However, then the user abruptly closes the Sidebar - leaving the physical changes already made to the spreadsheet (such as coloring). To undo those changes, need to hook into close event of Sidebar.
Any ideas / other ways ?

Google Chrome extension - integrate with Google Calendar

How can a Chrome extension alter the Google Calendar event editing UI?
I see that, for example, the Moxtra extension has managed to inject UI including a button just below the location. According to their YouTube video they added a button to fill out the event description although when I installed Moxtra this no longer seems to work.
Stepping back from this a bit, it occurs to me that editing the Google Calendar page seems like something that could easily get messed up by future changes to Google Calendar. Perhaps it is better to edit the event description from the extension's own UI? If so, how can that be done?
Thanks.
It can be done with content scripts and modification of the DOM.
They probably check Event edit page for specific selectors and try to insert their own elements in the page, if they found it.
So, if UI of Google Calendar will change, extensions like Moxtra will be probably also broken.
You are right about the edit of the description - it's safer. But you still need to get a description field and change a content of it. There is no 100% safe way to do it and don't break on the change of UI.

Modify a Google Slides presentation while presenting?

I'm afraid I already know the answer, but maybe someone else has found a way to do this.
I've been perusing the Slide Apps Script reference, and I'm excited about the possibilities. One thing I would like to do is alter a slide mid-presentation. Specifically, I would like to somehow indicate a link has been clicked.
If links in a presentation turned purple like web links I would settle for that, but I would like to use a trigger when a certain link is clicked or when a certain slide is shown. This trigger could run a script that alters the slide with the link appropriately to show the link has been clicked or even remove the link altogether.
I know the Slides API is behind the others, but Forms have installable triggers that can run onFormSubmit and Spreadsheets have triggers that run onChange and onEdit. I would love to see Slides have an onPresent trigger that ran a script that could detect slide changes with methods like onSlideChange that could report currentSlide. That way we could run scripts while the presentation is showing and take action based on current slides or links.
Aside from Slide specific triggers being added to the API, is there any way to modify slides during a presentation? Or at least show that a link has been clicked?

disable dismiss hyperlink and message on google spreadsheet

When we run any method of Google App Script,a message appears on Google Spreadsheet with dismiss hyperlink.
For Example:
Running Script methodname Dismiss hyperlink
I would like to know if there is any option to disable the message and dismiss hyperlink that appears on Google Spreadsheet when any function is executed at the back ground. In not , please share what alternates are available to hide this out.
It is within a div of class docs-butterbar-container so on your own machine, you could add
.docs-butterbar-container {
display:none;
}
to a user stylesheet.
But if you are hoping to hide it from other others of your sheets/scripts then your likely out of luck, unless you have means of rolling out user stylesheets.
I also wouldn't recommend hiding this. It's useful.

Google Apps Script: formPanel and doPost

I have a quick question concerning GAS efficiency and best practices. I have a script that is embedded into a site. In an effort to try and make it quicker I changed from using a doGet() with a serverclickhandler attached to a submit button and another submit() function to using doGet() with submit and doPost. The initial version used a vertical panel, while the second version requires a form panel. My vertical panel has a grid setup on it, and I would like to keep as much existing code as possible. My question is:
Can I put a grid directly into a formPanel without it slowing down the loading process? I tried it and it seemed slower, but maybe Google's server was having a bad day.
Can I add the verticalPanel to the formPanel without slowing things down? What would be the best practice in this situation?
The reason I want to switch to doPost is that it shows another panel when you click the submit button, so the user knows that there submission went through. Previously I was clearing the GUI elements, which seems like a lot of extra code that could slow things down.
Thanks in advance!
concerning the last point of your post, you don't have to clear everything, you can mask the whole panel with another empty (or not) one on top of it... quick and efficient ;-)
Depending on the way you created your Ui different approaches are possible : one of the easiest it to setVisible(false) the parent panel that holds all the widgets while you setVisible(true) a big label saying 'thanks for you answer... bla bla bla' (this one can be there from the beginning but invisible ;-) and set to visible by a handler on the 'submit' button (client or server... both are able to do the job))
Having panels inside other panels shouldn't slow down the loading of the UI.