How to import premade code in Google Script // Run a script from outside source inside of a running Google Script - google-chrome

I have come to ask if there happens to be a way to import code from a url or outside script file in Google Apps Script. I have tried the eval() method, but it does not seem to work with plain Google Script.
The problem is that I do not know of a way to actually import a Google Script through a method like UrlFetch.
I am trying to make my program similar to that of an injectable cheat script so the shorter the answer the better. Any help is greatly appreciated.
Thanks!
Here is something that I have tried:
function onOpen() {eval(UrlFetchApp.fetch("https://raw.githubusercontent.com/###/script.gs").getContentText());}
Something that I was expecting to see was the preset script in the URL getting imported and being functional as if it were in the main script itself. This, however, is not the result that you get upon trying this, and instead end up with a non-functional script and a waste of time.
Like I said, any help is greatly appreciated as I cannot find any answers for this problem online as I normally do.

Related

Cannot find the Google Script library I have already created

I finally got around to putting my script into a reusable library that I can share between other Google Sheets scripts. I have the URL (it opens to just the signature of the library functions) and the deployment ID.
It is definitely connected and working with my Google Sheet script.
I have no idea where the source code is stored so I can edit it! Believe me, I have Googled this. There is discussion on how to add your library to your script, but I could not find anything about editing an existing library.
I have searched my Google Drive.
I have looked in my Google Docs.
I have tried putting a break point in my script and stepping into the library function. (Note that this article says stepping into the library function should work).
Bubkis! Where is the darned code stored?!?!
thanks in advance
I think I figured this out. When you initially create the library, you are in a script. THIS is where the code is (I had assumed that a new library was created with this code.)

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.

Script to get a GooglePhoto using filename stored in GoogleSheets

I have a Googlesheets that has in one of its columns the filename (as "filename.jpg") of pictures stored in GooglePhotos (and/or Google Drive). I would like to have a script that would show me the selected picture when I click on a given cell of that particular column.
I'm quite familiar with Googlesheets Scripts and have looked at Google Photos API but don't know where to start.
Has anyone developed something like this and is willing to share? Any hints will be very much appreciated.
Many thanks in advance
I have a similar solution. You have to start from Browser API and this existing repo https://github.com/gsuitedevs/apps-script-samples/tree/master/docs/dialog2sidebar
But before that you have to realize the next flow:
Get a string
Try to search the file with this string
Return the file or undefined

Custom formula returning #NAME when Google Sheets is published to web

I'm not much of a programmer, but I managed to write a Google Sheets script that sorts an array, filters out specified values, and returns the new array. It works great.
However, when I publish the output page to the web, the link will only successfully show the output if I have the back end sheet open. As soon as I close it, the publish page turns up #NAME.
Presumably there is some restriction as to the availability of custom scripts. I assumed the output would just grab the text, but I suppose it's trying to run it and can't without someone being logged in?
Anyways - is there some way around this?
Thanks
Edit: Did a little further reading and found out that this might be a situation where "script as web app" might be the requirement. As a novice, this is a little over my head and I'd appreciate any advice.
I also tested to make sure IMPORTRANGE() as a source for this data wasn't the issue, and though it may cause other problems once I get the #name issue resolved, it does not appear to be at fault here specifically since the same thing happens with local data.
Yes, as you've stated, script as web app might be the requirement. You may also want to check this documentation regarding Custom Functions in Google Sheets. Just be noted that a script can be published as a web app if it meets these requirements:
It contains a doGet(e) or doPost(e) function.
The function returns an HTML service HtmlOutput object or a Content service TextOutput object.
Hope this helps!

How can I upload a dynamically created Google Apps Script?

I want to create a script dynamically and then upload it as a Google Apps Script.
When I try this, either
If I set the mime type correctly the link looks good, but doesn't work (file not found).
If I create a text file, that is just what it is - a text file, not a script file.
Do I need to wrap my code in an extra layer so that the editor can work with it?
Thanks
Michael
There's a way I've seen people implement something like this, but do so at your own peril: UrlFetchApp and eval(). You end up having to host the script somewhere else, pulling it back, and hitting eval() on the script somewhere. You may be able to do this via Google Drive sync and the DocList API.
An Apps Script API within Apps Script is something we've heard feedback for and are talking about, FWIW, but don't let this block you from getting what you need done in the meantime.