Google Scripts API: How to apply an onEdit function to every spreadsheet? - google-api

I wrote a little function that creates some menus and registered it with the onOpen() event with my spreadsheet in Google Drive so that the actions are triggered and the menus appear automatically whenever the particular spreadsheet gets opened. But there's a catch. I want this to happen for every single spreadsheet that I will ever have in Google Drive/Docs. Even the ones I create next week. Of course, I don't want to go through the process of registering a trigger for each particular document.
Is there a way to say "hey, every single spreadsheet in my account will have this function triggered on onOpen"? It seems like a highly usefull feature.
If this is not possible, can Zend's GData API for PHP somehow remotely run a script on a spreadsheet? Since all my spreadsheets come from a PHP web app, I could overcome the problem by triggering the execution from PHP.

If you're willing to change the way you create a new spreadsheet, rather than "Create New", then you should be able to acheive this with all your future spreadsheets.
Create a blank spreadsheet with your onOpen() code. Save it.
To make a new spreadsheet that has your menu, select your "template"
spreadsheet, use More - Make a Copy, and then rename the copy.
When you copy a spreadsheet, any included script is also copied. (Unfortunately, it gets named "Copy of...", but that doesn't affect functionality.)
Alternative: You can also use a Script Library with functions that you would like to change in future, and have the template script call them. (Libraries added via the "Manage Libraries..." dialog will be included in the copy.)

Related

Is there a way to launch userscripts directly from browser (Firefox)?

I would like to run some userscripts to backup data.
The same scripts could be used on a variety of websites.
Scripts are basically the same, only some configuration changes from one script to another (what to scrape on the page, and where to save it).
Scripts will not alter the page in any way, just read it then call some REST API with the data
I do not want these scripts to be loaded on every web page, as they won't alter them, and depending on the page there is only one I'd like to run anyway.
So is there a way to launch these scripts directly from the browser (Firefox) ? From a bookmark or something ? Basically I want to click a button and have the script run like if I was running it from the js console.
Best I found for now is the "#run-at context-menu" directive of Tampermonkey. My script appears in a TamperMonkey context menu and is run on click.
However this menu is loaded on every page (#run-at context-menu ignores the #include directive and is applied everywhere), I'm not sure of the performance consequences, and it might be inconvenient if I end up with lots of scripts.
I guess I could also modify my scripts to be run on specific pages so that they add a floating button or something. But I'd rather not modify the pages, and it would be inconvenient on pages where I'd like to have several possible scripts.
I remember using a Greasemonkey script that added options on the context menu a long while ago. Would that be possible with Tampermonkey, implementing an equivalent of the #run-at context-menu myself that would only work on some pages ?
A more native way would be best, but I'm open to options.
Basically I want to click a button and have the script run like if I was running it from the js console.
From above, I assume the userscript does not use any GM API or use #require since those are not available in JS console.
If that is the case, FireMonkey has a feature to inject script (or CSS) from the toolbar popup.
After saving a script and disabling it (so it doesn't run automatically) or enabling on sites that the script MUST run, users can select the script in the toolbar icon popup and click the button to inject the script in the active tab.
For temporary scripts, FireMonkey also has a Scratchpad that you can paste JS (or CSS) into and run on any webpage by clicking the button. FireMonkey remembers the last pasted data so that it can be reused.
Note: Except TM that alters the CSP of websites, other managers are bound by the webpage CSP.
Turns out there's a function for that: https://wiki.greasespot.net/GM.registerMenuCommand
Your script just needs to declare a function, call GM.registerMenuCommand("label", your_function), and it becomes available on click in the GM/TM menu.
Contrary to the other answer this means you can use #require.
Contrary to the #run-at context-menu this means you can use #match to only apply it to the intended websites
Notes:
GM_registerMenuCommand in TamperMonkey
Needs the #grant to use the function

How to create a batch script to find and replace pages within multiple documents

I have created several Word Templates and Forms (over 100). If any form in a template changes, all like forms in other templates must be updated as well. For example, if another field is added to the form, then I need to update 100 templates with this same added field. So, let's say the templates are saved according to client:
Q://Master Templates/Client Name/Client Template
(Note, the client template may have about 30 or more pages - like a contract and the form might be page 29 in this client, but another client may have 60 pages and the form might be page 20).
Then, there is another folder where the form is a standalone form, or part of a group of forms that are used together. Example:
Q://Master forms/Group Forms
Q://Master forms/Standalone Forms
First question: would it make sense to have a batch script that finds the form in each template or each folder; and then should the script find add replace the extra field, or does it make more sense to replace the entire form in the templates?
Second question: how would / could I do this? Is there a way to write the script to replace the form in each location based on the example above?
Third question: what types of security risks or problems such a batch script can create for an enterprise-wide network?
Thank you in advance for your support.
Probably the best answer is to use the Developer ribbon in Word. Within Word, File > Options > Customize Ribbon > Check the Developer item under Main Tabs.
Next, open one template needing changes and click Record Macro then make your changes.
Now you can open (In Windows Explorer, ctrl + click then right click to open multiple files) the other templates needing the changes and replay the macro to make those changes.
You could even record opening another document then just add the VBA code to open the other templates and play back the recorded macro to make the changes.
Here's the VBA to open a document in Word.
ChangeFileOpenDirectory "C:\Users\Administrator\Documents\"
Documents.Open FileName:="My File.docx"
Now once you get at least something partial, post back and we can help refine that.

Ribbon customization, always have access to a sheet

Hello competent people out there!
I have made a time registration sheet, that I use at my work place, in which I type in the hours that I am working on which assignment etc. Every time I need to use this sheet I find its physical location on the hard drive and open it. Through all day this sheet is open because I continuously has to registrate what I do. I want to get rid of this process.
My question now is: is there a good way to "put" this sheet up into the ribbon, so that I can access it from any excel workbook that I am working in? My first thought has been to add a button that simply opens up the workbook, but that wasn't exactly what I was looking for. I want to integrate this "time registration" into Excel itself.
Any input will be helpful.
Thank you very much!

Choosing between Excel Add-In, Template and Workbook?

I'm looking for some high-level help with determining the best type of Visual Studio 2010 project to use for an Excel custom application.
I will be developing a program that requires the user to enter a dataset in a particular way. Not using a form per se, but rather in columns and the program will need to do some custom validation on the items in order to prep the data. From there, the user will be able to conduct various operations on the data via a custom Ribbon and associated options. The program will also transmit the data via web service.
I've fooled around with the Add-In project and that gives me a lot of what I need but I'm wondering if a Template or Workbook project is better for this in terms of data entry and being able to "guide" the user a little more.
How do you go about choosing between which project type to use? Do all the project types support a custom Ribbon?
Sorry if this is too far off topic. I'm referring to VBA, not Visual Studio, but it might still be relevant.
With an AddIn, compared to a Workbook, you can separate your code from the user's data. So, if the code is complex, and you'll need to update it separately from user's workbooks with data, this is not a bad idea.
With an AddIn, you can add buttons that do things like check to make sure the user data workbook is ok, or process it in someway. However, the AddIn custom buttons will load ever time a user opens any Excel worksheet. This doesn't sound good, but in practice, isn't so bad. You can code your AddIn so it does nothing as long as no one uses a button, so it almost doesn't hurt load times, etc...
A Workbook might be useful if you need to really guide the user - that is, you cannot rely on the user to hit a button to verify something, and instead you need to verify on every change, for example. However, the workbook solution incorporates the user data and your code in the same workbook, so if you need to update the code for existing users' data, that's harder.
I use a combination of AddIn (.xlam) with buttons, and a template (with minimal self-describing data only).
I'm not sure about the template-only option, so won't comment on that.

How to detect back button -vs- GoBack() in WP7 app

Maybe I'm over-thinking this, but here's what I'm trying to accomplish.
I have two MVVM projects (assemblies) in my WP7 app. One page in the main project will call another page in the second project. The second page will allow the user to browse through a list of files on the web and select one to be downloaded to Isolated Storage. The files are rather small.
For a little background: I want two assemblies because this file-selection feature is not used often in the app and I want the Main assembly to be as small as possible to decrease startup time. I also want to be able to re-use this file-selection/download component in other apps.
The simple thing I'm trying to figure out is that when the user selects the file and it is downloaded, I will execute a GoBack() to return to the calling page. On the calling page, I need to know if, in fact, the user downloaded a file or if they cancelled out of the operation by simply hitting the back button. I thought the obvious thing might be to just check for the existence of the file in Isolated storage, but that just feel like a bit of a kludge to me.
I also thought about the Messenger, but I'm not sure how that would work across two assemblies.
Any advice would be appreciated.
Thanks
It is tough to know without looking at the code. However, I would suggest that you could pass back a value to the page depending on whether you successfully downloaded your file. Navigate with the value as follows (pass true or false depending on download success):
NavigationService.Navigate(new Uri(("/Page.xaml?download=true", UriKind.Relative));
Then evaluate the page in the destination as follows:
string download = "";
if (NavigationContext.QueryString.TryGetValue("download", out imageurl))
{
}

Resources