0

I have a Google doc which I regularly update and publish as a PDF. At the moment I have this script:

function onOpen() 
{
var ui = DocumentApp.getUi () ;      
ui.createMenu ('Automation')
  .addItem ('Download Newsletter as PDF', 'DownloadNewsletterAsPDF')
  .addToUI () ; 
}

I want to (preferably) replace the nested menu item click with a big fat button, but I can't see how to do that, so my fallback is to create an empty menu and bind my function DownloadNewsletterAsPDF to an OnClick event, if such a thing exists. If I change the onOpen handler to this:

function onOpen() 
{
var ui = DocumentApp.getUi () ;
ui.createMenu ('PDF')
  .addItem ('.', 'Dummy')
  .addToUi () ;
}

I can't have an empty menu so I need to provide a dummy item.

So how can I:

  • add a clickable button to the editor UI

or

  • generate an event when a menu header is clicked on.
rossmcm
  • 5,493
  • 10
  • 55
  • 118
  • About `add a clickable button to the editor UI`, unfortunately, in the current stage, the clickable buttons cannot be created. For example, the hyperlink can be set to an image. But I thought this might be not the result you expect. About `generate an event when a menu header is clicked on.`, can I ask you about the detail information of it? I cannot image about this. I apologize for this. – Tanaike Mar 06 '21 at 05:17
  • A clickable image would probably be OK, but I'm not sure if clicking an image can be made to execute a piece of script. What I mean by `generate an event when a menu header is clicked on` is that I want to execute a script routine when the text `PDF` is clicked on in my example. – rossmcm Mar 06 '21 at 08:32
  • Thank you for replying. When you want to run a script by clicking an image, how about using [Web Apps](https://developers.google.com/apps-script/guides/web) created by Google Apps Script? When the URL of Web Apps is set to the image, you can run the script by clicking the image. And, I think that you can also run the script using the custom menu. And also, you can run the script by clicking the text with the hyperlink of Web Apps. If these were not the direction you expect, I apologize. – Tanaike Mar 06 '21 at 08:39
  • Hi Tanaike, I am actually looking at [sidebars](https://www.youtube.com/watch?v=dyglOoU3Bqw) as an acceptable way of doing this. The video shows it used with a sheet but it should work for a doc. – rossmcm Mar 06 '21 at 12:29
  • Thank you for replying. I'm glad you found the direction for the solution. When your issue was resolved, can you post it as an answer? By this, it will be useful for other users who have the same issue. – Tanaike Mar 06 '21 at 12:36

0 Answers0