简体   繁体   中英

Can a Google Apps Script edit another Script?

Can you work with scripts like you can with Docs, Spreadsheets and Forms? ie. I can copy a Document by using DocsList.getFileById(fileId).makeCopy, and then edit the copy with DocumentApp.openById(fileId).getBody.replaceText.

Copying the file (per above) will also create a copy of the associated script, but there doesn't seem to be an equivalent ScriptApp...replaceText (there is a ScriptApp, but it does different things). Is there any way to programmatically edit a script?

I want users to be able to run a script that will copy my script and customise it for them, based on some input they provide to my script.

Apps Scripts projects can be imported and exported with the Google Drive SDK:

Documentation Import/Export

The Google Drive SDK can be run from Apps Script, but you need to explicitly enable it.

Documentation enabling Advanced Services

It looks like you can't edit a project file, so you would need to do any custom editing in a document, save the file, then retrieve the contents of the file into a variable, and then use the variable in the source parameter for the contents of a new apps script file to be created.

Documentation Create New Files in a Project

So, there are no methods in a service to directly do what you want. Not like editing a Doc. You'd need to either export the current file from your project, then import it into their project, or have a copy of the current Apps Script file in a Document that you then retrieved, and wrote to their new project file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM