I have a script in a google spreadsheet which changes the activated cell.
I you have selected A1 for example the script activates A3.
If you run it again it selects A5 and so on.
This is what it should do.
Now I want the script to be run timer-based in foreground.
I installed a trigger for that but the script only runs in background when started by the trigger.
Background is that I have a PC running, showing an overview list.
This List has now grown to be longer than the Monitor can display.
So I want the PC to automatically scroll through the document let's say one step every minute.
I could do it with an iteration but that would stop the script after the execution time out of 6 minutes while the script should run about 8h a day.
Any ideas how to solve this problem?
Don't use GAS for this. It runs server side with it's non-adjustable constraints.
Use something like an automator which will simulate keyboard commands. You can script it client side, by sending the "down" button to scroll through your list. Check "Autoit" for windows.
not possible using triggers as they can only perform server side work.
the only possible way with apps script is to open a sidebar from onOpen and use setInterval to keep calling your server function.
this also consumes less time quotas as most of the time is spent from clientside than relying on the 6minute server limitto keep updating state.
Related
I designed a rather simple Add-On to enable my local team to more easily automate newsletters and target updates to Slack.
The Add-On works well, aside from two issues:
Schedule a send functionality.
I'm using the ScriptApp's newTrigger() function to allow users to schedule automatic sends.
While it seemed to have worked in original tests, the triggers are now triggering at the wrong time (a trigger that should run daily from 11-12AM has been running at 5PM - Another that should run at 6PM has been running at 12AM - I've checked and the timezones appear to be correct GMT+2 for Paris)
GetActive() returning the wrong sheet
This is a minor problem as I've only noticed it twice, but when running a script with getActive() from the correct sheet, it accidentally ran the script using another spreadsheet.
I remain at your disposal should you need any more information, IDs or the likes.
Thank you for any help and have a fantastic day
I have a Google Script running every 5 minutes. It works except randomly there are sudden crashes and the script/trigger won't survive that. So, for many different reasons, the script stops running after some weeks of continuing runtime. At this point, I would need a notification.
How can I get a notification if a function (script) hasn't run in say 2 hours? Doesn't matter what the technique/notification is, but probably email would be great for the notification. I don't think the solution can be in the script code itself, because the script randomly (every few weeks) crashes at Google's side and there's nothing I can do about that.
Google Apps Script installable triggers automatically set an email notification. You could edit when it should be sent (i.e. send immediately) and you could add more notifications. NOTE: This can only be done manually.
The above will work for "normal" failures but it there is a service outage or other platforms failures the notification might not be sent.
One option is to log the executions somewhere then set a second trigger to check that the first trigger ran every time that it should do it as expected. NOTE: The failure that prevented that the first trigger run might also prevent that his second trigger run i.e. a service outage so you might want to set other monitoring measures accordingly the the severity/priority of this failure and your project budget.
I have a script that runs on a Google Sheets that is fed by a Forms entry. Basically, when I fill out a form, it creates an entry on the sheet. From that entry, a new document is created by my script that "prettifies" the fields on the sheet for distribution.
This sheet is located on a Team Drive, but in order to have the resulting document created in my drive, I had to place the unbounded script in my drive and reference the sheet. If I have it bounded to the sheet, it will always put the newly created document in the Team Drive -- which I don't want.
When it was bounded to the sheet, I had a trigger that would automatically create the document when the form was submitted. Now that the script is on my drive, triggering on submission is not an option. The only options I have are time based or calendar based, and neither of these really work -- unless I only want to get the document once a month or every single minute.
So now, the only way I know to execute the script is to do it manually every time, which is a major hassle and requires multiple steps no matter how you go about it.
Is there a way to trigger this script on command without having to open the Script editor, click the script I want, and then click run?
Why are there no keyboard shortcuts in Apps? I know about Ctrl+R -- but this only works if you already have the script you want highlighted in the top action bar. If I type Ctrl+R without it already highlighted, nothing happens. Nothing happens with Alt+R or Alt anything, really. I have tried simply tabbing 187 times to get to where I need, but the tab never seems to focus "in" the script menu area. It just bounces around the address bar, the shortcuts bar, etc.
NOTE: I do not want to make major changes to THIS script. It took forever to get this working right and I don't want to jack it up. I just want to be able to trigger it without having to go through 18 steps to do so.
There is no way to execute a standalone script project's function with a keyboard shortcut from within the Apps Script Editor. If your script was bound, you would have the option of keyboard shortcuts from the container Google Sheets file (as a google-sheets-macro), but macros have some restrictions.
However, you are not without options. Two of them:
Publish the script project as a webapp and use a page visit as the trigger.
Open the page / click a bookmark -> execute the function via your doGet().
Convert your script to a 'polling' style that processes any number of form responses, and use a time-based trigger (e.g. hourly, daily) to automate the whole process.
(Include a "did I process this response yet" flag to prevent reprocessing a response)
There are more elaborate configurations (e.g. Apps Script API + local cron job) but those are unlikely to be simpler than the above two options.
As I mentioned in my comment, you more than likely just needed an extra step for the original bound script to create the file in your Google Drive and not the host Team Drive. If you're interested in that avenue, you'll want to ask the appropriate (read: new) question.
This is a workaround not an answer.
I use the Alt/ menu to efficiently look up functions by name (For me, its faster than using a cursor to work thru the nest of menus). If you design your function names so they differ from the built-in function names, the lookup may take only a few keystrokes)
I am using a script which is found here: https://moz.com/ugc/updated-tool-seomoz-api-data-for-google-docs
I would like to trigger this to run once an hour (as a test, later once a month); to facilitate this I set up a time driven trigger in the script editor UI.
I need to test that the trigger is actually working. The issue is that I do not expect any of the data to change when the script runs (might change once a month max)...
So I looked to the script editor and found View > Execution Transcript. Perfect!
Except that I get this message:
No execution transcripts found. Please run your script and try again.
This doesn't seem to be consistent with the expected behaviour after reading the Google Apps Script documentation page, which says:
Every time you run a script, Google Apps Script records an execution
transcript, which is a record of each call to a Google Apps Script
service that is made while the script runs.
(Nothing in the logs either by the ways, though maybe this is something that needs to be turned on by the script itself; not sure).
So how can I test to see that my time driven trigger works, and that the script is being run each hour?
Final note: The script is executed by calling a function in the spreadsheet, as explained in the link at the top of the question.
If you have not yet run it manually, there may be an issue with it being given the proper permissions. Your first step would be to run the code manually using the play button. Once you know that the code itself will run successfully and has the right permissions, you can move to triggering it automatically.
Your next step is to shorten your trigger time so that it executes more frequently giving you more instances to check the function. Depending on the structure of your code, you can add Logger.log() calls at different steps to make sure that all portions are being called that need to be. You can then check you logs instead of the execution transcript as well.
These Logger.log() calls could include the time at which is was called to be able to verify that it was at the time/ frequency you need.
Ok, I don't know how great this answer is... but:
For me (as per my comment to MasterCrander), running the script by means of using the function inside the spreadsheet didn't actually affect the execution transcript, but when it ran via the time driven trigger it made it into the transcript.
Problem solved.
According to Google app script time-trigger documentation https://developers.google.com/apps-script/guides/triggers/installable#limitations,
Time-driven triggers cannot run more frequently than once per hour. How can I use app script to write an add-on that process large amount of data?
If I run a trigger, it will only allow me to trigger once. I can't chain the triggers so it can continuously run.
You cannot do so using triggers because they would run at most once per hour in the context of an add on.
What you can do is to initiate such processing client-side while possibly showing progress on a sidebar. The client js in the sidebar can chain server calls.Of course being all client-side means the user must have opened the file and if they close the browser tab or navigate away, the chain calls will stop. That can be handled by alerting the user and making them aware that a "sync" happens and sometimes takes a while. Currently there is no other way to handle this unless your client call and time trigger call another server which does the processing, like appengine or gce.