一个 google 脚本修改另一个脚本

A google script to modify another script

我基本上想在在线时运行脚本的一个版本,在离线时运行另一个版本(略微修改,只是删除一行)。因此,寻找一种方法来制作一个脚本来修改 Google Drive 中存在的另一个现有脚本。也欢迎任何其他选择。 似乎无法在 Google Apps 脚本页面上找到任何此类方式。 我正在考虑 link Windows 调度程序,但只需要一种方法来修改 google 驱动器中的脚本。

为什么不通过菜单添加自定义菜单和运行在线脚本。

然后运行项目触发器上的脱机脚本。在您希望的任何时间间隔使用计时器?

无法用另一个脚本修改一个脚本。好的,理论上你可以通过导入 javascript 并对其进行 eval 来完成,但没有必要这样做。
只需编码 "if" 并根据某些存储的设置执行其他操作。
在应用程序脚本中,您可以将该设置存储在脚本 属性.
中 将 属性 保存为:
PropertiesService.getScriptProperties().setProperty("offline", "yes") 并获得它:
if (PropertiesService.getScriptProperties().getProperty("offline")=="yes")

发布一个脚本(运行 为 "anyone, even anonymous"),它将根据 url 参数设置 "offline" 属性:
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 }

然后从 windows 调度程序中,使用 batch/script 文件获取 url(Windows batch file file download from a URL), GETting something like https://script.google.com/macros/s/xxxxx/exec?offline=yes 在登录期间。

注意计算机中的多个用户。在这种情况下,您需要为登录的 windows 用户传递一个额外的参数,并为每个用户保留一个设置。