Google docs install my own addon without publishing [duplicate] - google-apps-script

I have just made an addon for Google docs, successfully tested it and now I would like to use it. It's very simple, it just shows the id of the current document.
This is the most important part of the script, just called by the onOpen(e) function:
DocumentApp.getUi().alert(DocumentApp.getActiveDocument().getId())
When I tested it by the Publish/Test as addon (I am not sure with English titles, I translated the button names from Czech) it works exactly as I want.
How can I use it the same was as I would download it from the webstore? I don't want to publish it, because it isn't much useful for others and I would have to follow the rules, wich Google wants. Is it possible?

You can publish it privately.
This way you can publish it instantly (google doesn't need to review it), it's only visible and install-able by you, and you don't have to pay the developer fee.

In the Chrome Web Store developer Dashboard:
Developer Dashboard
You can add an "Item" to be published as a draft. Then, you can edit the item before publishing it. At the very bottom of the "Edit Item" page, there are 3 settings for visibility options. The last one is "Private"
An Apps Script bound to a Doc runs the onOpen() function without publishing the script as an Add-on, or Deploying the bound script as a web app. Publishing an Add-on, and deploying a web app are two totally different things. But, you don't even need to do either of those. All you need to do, is open the Doc that the Apps Script is bound to, and the onOpen() function will run. Also, you don't need the e argument in onOpen(e). That's for an event parameter.
Something else that's interesting is group based publishing:
Group-Based Publishing in the Chrome Web Store

You can not by pass the payment process i suppose. As earlier comments mentioned; you can pay the developer fee (as i remember it was like a 5 dollars) and publish it as private. So nobody can see and install it.
But if you want to use as test you can run the script as test on a document. Select the "Run->Test as add-on..." menu and you have to select a document. After selecting and openning that document you will see very long text on address bar like this:
https://docs.google.com/document/d/your_document_id/edit?addon_dry_run=bla_bla_bla
So just take the
?addon_dry_run=bla_bla_bla
part after the
https://docs.google.com/document/d/your_document_id/edit
and paste to your other documents :) Your add-on menu will work. But i can not guarantee if that works for only your account or a security leak! Use at your own risk.

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

How do I build a Google Add On with a menu item that pops up in all documents?

I'm new to Google Apps Script, so forgive me if I use the wrong terminology. I'm trying to build a Google Apps Add-On but I'm having trouble piecing things together. Ideally I'd like to add a right-click menu to all documents when someone installs my Add-On. Similarly to how LucidChart adds a top level menu to all docs.
https://developers.google.com/apps-script/reference/base/ui#createAddonMenu() says:
If the script is running as an add-on, the sub-menu name matches the add-on's name in the web store; if the script is bound to the document directly, the sub-menu name matches the script's name.
Should this work in an Add On:
function onOpen() {
DocumentApp.getUi().createAddonMenu().addItem("Test", "test").addToUi()
}
function test() {
DocumentApp.getUi.alert("Yeah!")
}
and if so, what am I supposed to do after doing this to trigger onOpen on all the documents I open in my account? I mean, at the moment, just to test this add on (that is, to start developing it). I'm not sure what to do to run it.
You should create a unbound/standalone script when creating a addon. But it'll become bound to the document, when a user installs the addon on that document. See Authorization modes.
I'm piecing together an answer. There are currently two editors for Google Scripts, the current one and the legacy one. I still don't know if it's possible to test an add-on with the current one, but it seems possible in the legacy one.
To switch from the current one to the legacy one, there's a link on the top right:
Once in the old editor there's "Run" menu:
that has a "Test as add-on" function:
That opens a dialog that allows you to open another document with the add-on installed, enabled, or both:
Before finding this out, I enabled showing the script manifest, added the "addOn" entry, and deployed as a Test Add On in the new editor. I'm not sure if that had an effect.

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.

Publishing a Google Docs Add on

I have built a Google Script which is currently bound to my present Google docs document. It is a simple script that has a menu item and a Sidebar. I wish to access it from all my google docs document. I think the way to do it is publishing it on the Chrome Web Store as an add-on. It requires a developer fee of $5 which I have no problem paying but I want my script to be private(or shareable only to selected few) because it contains my API key that I don't want to share.
Please let me know if there is any alternative except publishing it as an add-on
If I publish it, can I use it privately and not share it. if that is true then how to do it.
If there is totally another way to do this, I'm all ears.
Sorry if that is a trivial question, I am a complete beginner.
P.S. I read a few answers saying it can be done but from my knowledge Google has updated the conditions, so wanted to verify before giving the developer fee

How can I change my script to AuthMode.LIMITED in my Google Scripts code?

I was trying to publish a new version of an Add-on that was already created, but when I tried to publish it, I can see the menus, sub-menus and I can execute the Add-On Picture 1. The problem is that the other users -who before were able to execute the Add-On- now they don't see the sub-menus and obviously they can't execute the Add-On Picture 2.
I Googled a little bit and I was investigating about this, so I found that there is a method called AuthMode.NONE and AuthMode.LIMITED, I know the differences between them but I don't know how Google Scripts classify the Add-Ons and how to force change the AuthMode to LIMITED, or maybe you can give me another solution that can help.
BTW: I already checked if the Add-On is activated for my document and yes it is, I mean that i have the option: Add-Ons --> Manage Add-Ons --> [my addon] --> Manage --> Use in this document checked.
PD: I tried uninstalling and installing the Add-On, publishing and re-publishing new versions, I tried a lot of things but no solutions.
Thanks in advance!
This read on Authorization modes may help:
If an add-on is installed for a user but not enabled in the current
document, onOpen(e) runs in AuthMode.NONE; if the add-on is enabled in
the current document, onOpen(e) runs in AuthMode.LIMITED. If the
add-on is both installed and enabled, the enabled state takes
precedence, since LIMITED allows access to more Apps Script services.
Note that only published add-ons can be in AuthMode.NONE; scripts that
are bound to a document, including add-ons in development, always run
onOpen(e) in AuthMode.LIMITED. You can, however, test a script as an
add-on to verify that an add-on under development will behave as
intended in either AuthMode.
Check this SO thread for additional reference.