一个人可以遍历绑定的脚本并通过脚本编辑其清单文件吗? [英] Can one iterate through bound scripts and edit their manifest files via a script?

查看:74
本文介绍了一个人可以遍历绑定的脚本并通过脚本编辑其清单文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个拥有许多用户的应用程序,每个用户将拥有许多Google文档.每个文档都有一个自定义菜单,该自定义菜单将调用一个库脚本.我可能需要或想要不时更改该库脚本中的编码.

I am building an application that will have many users, each of whom will have many Google documents. Each doc will have a custom menu and that custom menu will invoke a library script. I may need or want to change the coding in that library script from time to time.

由于必须将对库脚本的更改保存"为新版本,以便将更改的版本传递到客户端脚本(在我的情况下,该脚本绑定到Google Docs),因此我需要一种用户可以在其文档的绑定脚本appsscript.json中批量"更新版本号 文件.

As changes to a library script must be "saved" as a new version in order for the changed version to be passed on to client scripts (in my case, the scripts bound to Google Docs), I need a way that users can "batch" update the version number in their docs' bound script appsscript.json file.

我已经研究了这个问题,似乎有两种通用的选择:将客户端脚本的库模式设置为开发"或使用附加组件.

I have researched this issue and there seems to be two general alternatives: set the client scripts' library mode to "Developmental" or use an add-on.

前者的问题是,除非所有用户都被授予了对库脚本的编辑模式访问权限,否则它将无法工作(这似乎是一个坏主意,因为用户可能甚至不被我所认识).

The problem with the former is that it won't work unless the users are all granted edit mode access to the library script (which seems particularly a bad idea as the users may well not even be known to me).

后者的问题本质上是复杂性和成本.如果我将附加组件设为私有,则该附加组件仅适用于同一域中的用户,这意味着我必须创建一个G-Suite域(并(至少在撰写本文时)每年为每位用户支付$ 72,这是非入门级的这个项目).

The problem with the later is essentially complication and cost. If I make the add-on private, it only works for users in the same domain which means I have to create a G-Suite domain (and pay at least (as of this writing) $72 per year per user—a non-starter for this project).

如果我将插件公开,那么除了麻烦之外,我还必须注册Google Cloud Platform,其成本要求人们在选择和替代方案的真正迷宫中导航,以便在这一点上,我真的不知道每项服务或每位用户的成本是多少.

If I make the add-on public, in addition to the complication, I have to sign up to the Google Cloud Platform and the costs for that require one to navigate a veritable maze of choices and alternatives such that at this point, I really have no idea what the cost per service or user would be.

下面,我提供一些模拟"代码,至少应指出我要去的方向.

Below I present some "mock-up" code that should at least indicate the direction I am trying to go.

function upDate() {
  var version = 23
  var scripts = "https://script.google.com/u/0/home"
          //while (scripts.hasNext()) {
            //var script = files.next();
  //Note: All of the script's have the same name as they commence life bound to a template, which template is duplicated to create the rest of the user's docs
  if( scriptName = ScriptName){
            //set.dependencies.enabledAdvancedServices[].version
}
}

我什至不知道是否有可能像浏览Google云端硬盘中的文件一样单步执行绑定脚本,因此这是第一个问题.然后,第二个问题是,假设您可以一步一步地执行脚本,是否可以更改清单值(在这种情况下为版本号).

I don't even know if it's possible to step through bound scripts the way one step's through files in a Google Drive, so that is the first question. Then, the second question is whether, assuming you can step through the scripts one by one, you can change a manifest value—in this case, the version number.

推荐答案

一个人无法浏览容器绑定的脚本,因为它们(不再)位于一个人的Google云端硬盘中.此外,尽管Google在清单清单的版本部分中提供了有关使用稳定"值的文档,但该文档似乎是错误的.最后,不能以编程方式编辑独立脚本.

One cannot step through container-bound scripts as they are (no longer) located in one's Google Drive. Moreover, despite Google's documentation about using a "stable" value in the version section of the manifest, that documentation appears erroneous. Finally, one cannot programmatically edit standalone scripts.

但是,有一种解决方法.我最终要做的是编写一个脚本,逐步浏览所有涉及的Google文档,并将其复制到空白模板(即实际上将它们全部复制).该空白模板中安装了绑定脚本,并带有库的新版本号.然后,删除原始文档(通过相同的脚本)并voilà,完成对所有目标文档的批量更新. (这样做的一个缺点是:如果Google Doc修订历史记录对您很重要,请告知我们(除非您保留原始版本).

However, there is a workaround. What I ended up doing was writing a script that steps through all of the involved Google Docs and copies them to a blank template (i.e., in effect, duplicates them all). That blank template has the bound script installed in it with the new version number of the library. Then, delete original docs (via the same script) and voilà, batch update to all of the target docs is accomplished. (One drawback of this is: if Google Doc revision history is important to you, be advised this gambit jettisons that (unless you keep the original versions).

这篇关于一个人可以遍历绑定的脚本并通过脚本编辑其清单文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆