Google Sheets script : Click on menu item - google-apps-script

I'd like to have a script that simply clicks on File > Download > PDF of a Google Sheets menu.
To simplify, I first tried to have the script click on "File".
With devtools I could determine that this menu item has id="docs-file-menu" so my function should look like :
document.getElementById('docs-file-menu').click();
But it doesn't work because document is not defined.
While searching for a solution, I understood that Apps scripts cannot interact with the browser, but I'm not quite sure whether that includes the sheets menus items as well?
Is there any way to make a script click on a menu item?
If not possible, is there any other way to make the "download as pdf" window appear?

Related

Use Google App Script to prevent user opening url link in Sheets if site is already open in another browser tab

I've got a Google Sheet that contains numerous hyperlinks.
I'd like to prevent the user from opening multiple instances of the same site.
ie. user clicks the hyperlink in one cell which opens the linked site in a new tab, then attempts to click the same hyperlink while the first new tab is still open - I'd like a dialogue box to appear saying that they cannot open this second new tab until they have closed the first one.
Is this possible via Google App Script?
Many thanks!
Unfortunately not. GAS has no access to your browser data and cannot know what tabs are open.Moreover, GAS has no way of intercepting hyperlink clicks from within a spreadsheet, it can only do that in a side bar, modal (or modeless) dialog, a custom or an add-on menu or an image with a script attached to it.

How can I change order of custom menu in Google Sheets?

I am creating custom menu items for Google Sheets.
On the picture from manual, "Custom Menu" is moved to the left of "Help" built in menu.
Whereas by default the custom menu is placed to the end (to the right).
I didn't find related methods in Menu class per se.
The reason is to call my scripts by keyboard shortcuts, moving through menu items.
So far the only customized shortcuts are available via useless inconvenient macro.
unfortunately, this is not possible in Google Sheet, yet.
if a macro is inconvenient you can perhaps use some 3rd party tools like AutoHotKey.com

Is there a way to call myFunction() from an image, button, or link within a Google Doc, rather than using the menu?

I know that in Google Spreadsheets, you can bind a custom script function to the click event of an image, at least manually via the UI.
But in Google Docs, there doesn't seem to be any equivalent functionality. The only options are timers, onOpen() and ilk, and creating a menu item at the top.
Am I missing a way of adding a function launcher somewhere on the doc itself, especially dynamically from a script? I've searched a bunch and pored over the API docs, but I'm not seeing it.

Can I add item to Google Docs right-click menu for my Add-on?

I'm writing an add-on for Google Docs, using Google Apps Script and I see that I can add actions to the Add-ons menu using DocumentApp.getUi().createAddonMenu().addItem. My current action launches a sidebar. But that's several clicks away from the user. I'd like to put an option on the right click menu and / or make the action available via a hotkey.
Is there a way to add to the right click menu or create a hot key to launch my add-on item?
You could just launch your sidebar in the onOpen event for the spreadsheet and it will be there right from the start.

google app script documentation clear formatting api

I would like to write a google app script to automatically clear the default text formatting of my uploaded/converted google text documents. When editing a google document in google drive, this can be done manually by selecting the text and clicking the the "Format\Clear formatting" drop-down menu item.
I am wondering if there exists such google app api or apis or any other suggestions for doing this programmatically?
Google Apps Script can't run on document upload. So you can't do this without having to install script on every document. And it takes longer than just pressing Ctrl+A and clicking the clear formatting button.