I basically want to run one version of a script when i am online and another (slightly modified one, just to delete one line) when i am offline . So, looking for a way to make a script which modifies another existing script present in Google Drive. Any other alternative is also welcome. Couldnt seem to find any such way on Google Apps Script page. I was thinking to link Windows Scheduler but just need a way to modify the script in google drive.
2 Answers
Not possible to modify a script with another script. Ok theoretically you could do it by importing the javascript and doing eval on it, but there is no need to do that.
Just code the "if" and do something else based on some stored setting.
In apps script you can store that setting in a script property.
save the property with:
PropertiesService.getScriptProperties().setProperty("offline", "yes")
and get it with:
if (PropertiesService.getScriptProperties().getProperty("offline")=="yes")
Publish a script (run as "anyone, even anonymous") that will set the "offline" property based on url parameter:
function doGet(e) {
var isOffline=e.parameter.offline;
if (isOffline !== undefined) //parameter must exist
PropertiesService.getScriptProperties().setProperty("offline", isOffline);
//here you can just stop or return a value using ContentService
}
And from windows scheduler, fetch the url with a batch/script file (Windows batch file file download from a URL), GETting something like https://script.google.com/macros/s/xxxxx/exec?offline=yes during logon.
Watch for multiple users in the computer. In that case you would need to pass an extra param for the logged-in windows user and keep a setting per-user.

- 1
- 1

- 19,571
- 5
- 26
- 36
-
yeah, thats why i was gonna use windows scheduler , to run script on startup and logoff. I was planning to run the script by a mail trigger , but i guess since it doesnt work , so nevermind. – Pulkit Jan 03 '15 at 16:03
-
Yes you can use windows scheduler to run a content script webapp. Store the offline/online setting in a script property. Use that property in your script. Email triggers can also work, not sure why you say they dont work. – Zig Mandel Jan 03 '15 at 16:16
-
Im adding my last comment as part of the answer, as it seems thats what you want. – Zig Mandel Jan 03 '15 at 17:03
Why not add a custom menu and run the online script via the menu.
Then run the offline script on project trigger. using a timer at whatever intervals you wish?

- 958
- 11
- 28