As a workaround to what @Tanaike proposed you can use the Drive API to make the copy. Because bounded scripts are also copied when you perform a makeCopy() operation.
Steps:
- Create a new sheet and add a bounded script via
Extensions > Apss Script. Take note of the ID, in the example I will call it SSA_ID
- Add your script. As probe of concept I just added this simple one:
function onOpen(e) {
SpreadsheetApp
.getUi().alert('Hi from bounded script')
}
- Create a new script, and paste this code inside:
function copySpreadSheet() {
const file = DriveApp.getFileById(SSA_ID)
const newFile = file.makeCopy(`SpreadSheetCopy_${new Date().toISOString()}`)
Logger.log(newFile.getUrl())
}
- Run the script, grab the url and copy paste it in your browser. You will see that it contains a copy of the bounded script.
From there you can manipulate the copy and add it to an Installable Trigger, for example:
ScriptApp.newTrigger('copySpreadSheet')
.timeBased()
.everyHours(6)
.create();
Documentation:
Is it possible to add an existing app script to a newly created googlesheet using app script?, you can achieve this using Google Apps Script API. Ref AboutAnd automatically assigning it to a trigger?, for example, how about creating both the Spreadsheet and the container-bound script using a script?