Google Apps Script Spreadsheets - Assign script to image from a script - google-apps-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.

Related

How to avoid saving a google sheet and have multiple people editing at the same time?

I’ve created a Google Sheet – kind of like an app – using script. It’s a number of blank cells where once added some information, it creates a string with that information in the right order. I created this to help some colleagues. We are using free accounts.
I face 2 problems:
The app is supposed to be used by only one person at a time, but I’m sure at some point two or more people will want to use it at the same time. Is there a way to allow this without they interfering with each other? I’ve read you can share a link that creates copies of your doc, but that wouldn’t work in this case because I intend to keep updating it regularly.
The changes people make to the sheet will stay there. Right now I have a onOpen function that just rewrites everything, but if someone accesses the document while someone is using it they’ll rewrite everything and ruin their work.
Any ideas on how to solve these two problems? Thank you so much in advance!
I think that you have to find another way to implement your "app" because Google Sheets not a good tool for limiting that only one user edit a spreadsheet a time, but if for any reason you decide to keep with it,...
... you need to implement a workflow like the following
Save the active user email on PropertiesService.getUserProperties().
This should be done by each user by running a script themselves. The most user-friendly will be by using a macro, custom menu or button (a drawing with an assigned Google Apps Script function). You might use an open installable trigger to validate that the active user have already done this.
You might have to make the function that clears the data a "smart" function.
You might have to consider additional cases, like if the owner of the spreadsheet opens it when there is an editor working on the spreadsheet.
Use installable triggers to manage the sharing settings.
Use an open trigger to remove all the editors except the active user
Use a time-driven trigger to add again the editors. To make this work effectively should define how the time-driven trigger will know that the last editor have finished their session, i.e. you might use DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId()).getLastUpdated()
The above should help you with both problems, as long you as the owner do not open the spreadsheet as is used by someone else.
Other alternatives that might work better is to create an add-on or a web application.
Related
Determine current user in Apps Script
Last modified date in Google App Script GAS sheets

Is it possible to add the same custom menu to every new google document? The goal is to make a local script function like an installed app

Is it possible to add the same custom menu to every new google document? The goal is to make a local script function like an installed app.
This seems like it should be easy but I can't seem to find a way to do it. I'm using a standard account for personal use. I've created a script attached to the original document and also made copy as a stand alone script. (I'm not sure that makes a difference.) I've searched and read about deployment and it seems to be only useful for a domain account or publicly as an app. I've played a little with scripting but this is the first attempt to get a script working "globally".
Any help will be most appreciated.
I found a way to do this in an old example at: https://sites.google.com/site/scriptsexamples/custom-methods/2d-arrays-library.
The script is in a project and that needs to be connected to the current doc. The onOpen() script is a UI that contains the line:
.addItem('Select Phrase', 'PS.showPrompt')
where PS is the name of the attached library. Once this is done, as you said, you can make a copy and use it with the script active.
It is a little slow as they describe about using a library, but is make the code easier to maintain. Thanks to all for the direction to look.
What we do is create a copy of the original document (the document with the attached google apps script). The script is copied along with it and the copied document has the exact same functionality (menus, custom functions, etc).
You could create a Google Docs Add-On using an independent Apps Script script and then install your Add-On globally. For more information regarding its installation check this documentation. However you would need to run this Add-On on the new documents to get your desired menu.

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

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"

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.

How can I let others install my Google Apps Script?

I've made a simple script in Google Apps Script. The script builds forms based on a spreadsheet, the script itself is part of the spreadsheet. It adds a menu item. People would like to use it. They are non-technical people, so I would like to make the installation of my script as easy as possible. With 'installation' I mean a way to 'import' my script into their spreadsheet and automatically set up the needed triggers so the menu item becomes visible. It should be possible for anyone to install it.
I've been thinking of the following solutions:
Publishing as an add-on: my script wouldn't qualify, and even then I can't wait for Google's approval.
Copy-paste. I don't like this, it's way too complicated.
I've looked at this question: https://stackoverflow.com/questions/5334751/how-do-i-share-a-script-i-wrote-with-my-co-workers-on-the-same-google-apps-accou, but the people wanting to install it are not on the same domain in my case. The question is also 3 years old.
EDIT: As it turns out, there doesn't seem to be a solution. I've filed a feature request here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=4122&thanks=4122&ts=1403949074
If your Google Account administrator allows you, you can share scripts/spreadsheets outside your organisation either by sharing directly with another person with a Google Account (Gmail or Google Apps) or by making it public (share with a link or published online).
https://support.google.com/drive/answer/2494822?hl=en
Keep in mind that if you use the Script Properties to store values, each time someone uses the shared script it will overwrite the values. In a shared context it is best to use User Properties instead. This way each user can store their own values.
https://developers.google.com/apps-script/guides/properties
There is no way to import a script in an existing spreadsheet , the "normal" workflow is , in a way, the reverse process, that's to say create a sheet from an existing template that already has the script in it and start to work with that copy.
From your description I'm not sure this method could be useable but I'm afraid there is no other way if you want people who will be using it should not go into the script editor at all.
There would be a couple of functions to write that should run at install time and would create the triggers (if needed) and trigger the authorization process.
I made such a SS some time ago that needed authorizations and I added an "install" menu that made its use quite simple (example here on a friendly hosting site).
I know this is probably not the answer you were expecting but it was definitely too long to fit in a comment anyway.