Launching special links from a selected or clicked cell in google sheets - google-apps-script

Google sheets restricts which link types can be launched (https://support.google.com/docs/answer/3093313?hl=en), but with google apps scripts I was hoping to build a workaround so that people can launch an internal app with relevant information (ie App:123132). onSelectionChange would seem to be an option (when the user selects the cell with the relevant link, open the app) but it's not an installable trigger, limiting what can be done (specifically, I can not launch a new page or try to redirect to a uri such as App:34234). The other triggers don't seem to provide the functionality to do this without polling, which doesn't seem to be the right way to do this. Is there any other way people are aware of to make this happen?

Without polling there isn't another way to make this happen. As you already mentioned there aren't simple/installable triggers able to open a link.
By using Google Apps Script one option is to create a web app to show the content of the "special link".
Another option is to use a dialog/sidebar to use client-side code to open the "special link"

Related

How can I "publish" an editor add-on to be used by just me?

I'm involved in a standards development group where the meeting invitations are sent out, not as calendar invites, but as Word docs. I've written a script that allows me to take the Word doc uploaded to Google Drive, and run the script to create an entry on a Google calendar that I maintain.
At the moment, the script is unpublished, and to run it on the docs I use the "Test as Add-On" function from the script editor. That's a bit cumbersome because I have to go through the selection dialog to select the doc I want to run it on. Additionally, in the new scripts editor, it won't be possible to delete old tests and so my test dialog will end up getting filled up with every run of the script I've ever carried out.
It would be much better if I could have the script available to me, and me only, from the Extensions->Add-Ons menu when I open a doc. The script is not suitable for general publication: it works only on docs with the exact format of these meeting notices, so it should only be run by someone who knows what they're doing, and it accesses a calendar that I own, so I don't want to make it public. But I would like to be able to put it into some kind of "deployed" state so that, as I say, when I open any doc when I'm logged in as me, the script is just available directly from the Add-Ons menu.
Is there any way to achieve this? Or is there an alternative approach possible to this general problem, of having a script that you want to run on multiple documents that you own without having to formally publish it?
One option to "test as add-on" without publishing the script as an editor add-on, is to use installable triggers instead of simple triggers. This triggers should be created by using code in order to avoid having to add any code to each spreadsheet.
If you are determined to take the publishing path you can set your add-on listing to be "unlisted", this means that the add-on will not appear on the Google Workspace Marketplace, people will need to know the installation URL to be able to install the add-on.
Other options:
If you have a Google Workspace account you could publish the add-on privately for your domain. If you don't have this account type or if this is "not good enough", you might make your Google Apps Script add-on publicly installable but limit its core features to be used only by you by making use of a dynamic custom menu. For details please checkout Editor add-on authorization
The dynamic custom menu might based on a setting depending on the user email address. To make this work, as the Session.getActiveUser() requires authorization to run, it can't be executed by simple triggers, but you might implement a workflow to save it or a flag, i.e. add an option to the custom menu to initialize the editor add-on.
Another option is to make the dynamic custom menu based on the spreadsheet structure and/or content.
References
Installable Triggers
Enable and configure the Google Workspace Marketplace SDK
Related
Google Apps Script: Dynamically creating spreadsheet menu items
Publish an add-on privately

Google Sheets Script not sticky

I am trying to create a custom function for a Google Sheet. to do this, I start from within the Sheet that I want to use the function, I then go to the menu Tools|<>Script Editor.
I then write a function. Name the file. And save it.
But, I can not use this function. Error #NAME?
Then if I close the Script Editor and open it again, it's like I have never been there. It presents the same form you see when you first start.
From an OP comment
I have discovered the issue, but not the solution. When the script editor is opened it switches me to another Google account I have. So I switch back. But then I am presented within a screen saying Acess Denied and making me ask permission. To whom and what for I am not sure.
The solution to the root cause of the problem depends on Google, fortunately there are several workarounds.
Use Chrome in incognito mode with all the extensions disabled, then sign in on only one account (the key part is bold)
Use another web browser or web browser profile. Sign in on only one account (the key part is bold)
Signout of all your Google accounts, then sign in first on the account that you will be using for developing your scripts, then sign in on the other accounts. This still migth be problematic under certain circunstances.
Also, as good habit, when you click Tools > Open script editor to create a new bounded project, the first thing that you should do is give a name to your project.
Another god habit, before testing a custom function, be sure that there isn't a project file with a red asterisk (unsaved file). Contrary to spreadsheets, the Apps Script files aren't automacatily saved when a edit is made.

Securing A Google Sheet With A Custom Generated License Key

I am trying to secure a heavily customized Google sheet so that it may be licensed out for personal or commercial use, and am looking to secure the sheet by generating and sending the user a license key that they may paste into the sheet to unlock it.
I have checked this answer below for how to create the dialog box/popup, but am not sure if this would sufficiently stop people from just closing it out/bypassing verification.
https://webapps.stackexchange.com/questions/80213/create-a-popup-in-google-spreadsheet
I'm also considering tying all of this into Firebase for ease of use.
Has anyone every done this before or know if Google sheets has this capability?
Thanks!
The method of creating a dialog box or pop-up won't work because the user who will get access to the sheet can just simply close it.
According to the Dialogs and Sidebars in G Suite Documents documentation:
An alert is a pre-built dialog box that opens inside a Google Docs, Sheets, Slides, or Forms editor. It displays a message and an "OK" button; a title and alternative buttons are optional. It is similar to calling window.alert() in client-side JavaScript within a web browser.
Therefore, what you are trying to do cannot be done.
By default, all the Spreadsheets you create can be viewed and edited only by yourself.
The only way to restrict or extend the access to a Spreadsheet is by using the sharing settings.
If you want to protect a certain range or sheet from editing, you can protect a sheet or a range. Please note that this still allows the viewing of the sheet or the range.

Using Google Sheets Menu with Google Apps Script

I am new to Google Apps Script and looking for some insight into a feature I would like to implement.
I am using the Google Analytics add-on inside of Google sheets to report on our site. I have already set up a script to send out daily reports, but currently still have to run the reports manually using the add-on. Is there a way I can access the add-on menu using Google Apps Script?
I'd like to add the functionality of clicking 'Run Reports' in the GA add-on menu before my daily email script. Any help would be greatly appreciated. Thanks!
I think what you mean is you're inside a sheet, and you want to be able to press Add-On->Add-on Name to run the report.
You're not able to do this unless your script is a published Add-on available on the add on store for anyone to download. Given the restrictions Google currently has in place for that, it's unlikely you'll want to do that.
Instead, you want to create a custom menu. An example found here. I'm not going to bother copy/pasting their sample, as I'd be leaving it as is.
From the sounds of it though, you might prefer to create a time based trigger. The simplest way to do this is open your script, press 'Resources' -> Current projects triggers -> 'Click here to add one now'. This will allow you to set a time based trigger to run every day for example.

Google Apps Script Spreadsheets - Assign script to image from a script

I want to generate images with a script assigned to it using another script. I know you can insert images from a script link here, but I can't find a way to assign a script to that image from a script. I found someone requesting this feature here, but with no solution or workaround. If someone knows any way to insert a button that runs a script from another script into a spreadsheet, I would like to know it.
Edit: I have thought about using a trigger that would get the event source container and run a script on cell edit described here sort of, but I would love a gui.
This would be a cool feature, but here is a possible workaround, it might even offer more functionality.
You can build a UI using Google API.
More detailes here.
The UI allows you to create side bars/menus/etc. You could even create floating dialog windows. Using AbsolutePanel, you can even choose where the dialogue shows up.