Question

If I have a Google Apps Script that does some processing to a single gmail message, how can I trigger it from the gmail web interface so it gets applied to the message I have currently open on screen?

The closest way I've found is to apply a label and have a background process monitoring labels. Is there a way to add a button or menu option to gmail instead?

Thanks

Was it helpful?

Solution

No, there isn't. At least not using any "native" Apps Script or Gmail feature. You'd have to write a browser extension to achieve this.

Another thing you could do (aside from the special label) is to gmail's URL (while viewing the message) and paste it in your Apps Script interface (previously opened in another tab). Then your script can extract the message id from the URL and work on it right away.

Also, you could do something clever like having your script receive the id (or full gmail url) from a parameter on the script's own url, e.g. https://script.google.com/macros/s/<your-script-key>/exec?gmail=<url>

Then set up your browser (I know Chrome and Firefox do this) to trigger your script and pass the parameter based on a keyword in the location bar. I use mostly just one letter (like "y script" searches the word "script" on youtube. If you use for example "a", you could hit ctrl+L (select location bar), ctrl+c (copies gmail url), ctrl+t (new tab), then type "a ", ctrl+v, enter. Not exactly clicking a button on the gmail's interface, but does the job rather easily. If you're inclined to keyboard shortcuts like I am, this is even a preferable way :)

OTHER TIPS

Another options is to label your message with some label and have an app script scan for this label every X minutes and process all messages it finds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top