Using Google Apps Script, you can modify your scripts so that before running they unprotect your sheets and ranges, and after running they re-protect them. You could use code such as the following:
function unProtectAndProtect() {
var sheetProtections = SpreadsheetApp.getActive().getProtections(SpreadsheetApp.ProtectionType.SHEET);
var rangeProtections = SpreadsheetApp.getActive().getProtections(SpreadsheetApp.ProtectionType.RANGE);
var protectionData = {
sheetProtections: [],
rangeProtections: []
};
for (var i=0; i<sheetProtections.length; i++) {
var protection = {};
protection['editors'] = sheetProtections[i].getEditors();
protection['description'] = sheetProtections[i].getDescription();
protection['range'] = sheetProtections[i].getRange();
protection['unprotected ranges'] = sheetProtections[i].getUnprotectedRanges();
protection['candomainedit'] = sheetProtections[i].canDomainEdit();
protection['iswarningonly'] = sheetProtections[i].isWarningOnly();
sheetProtections[i].remove();
protectionData.sheetProtections.push(protection);
}
for (var i=0; i<rangeProtections.length; i++) {
var protection = {};
protection['editors'] = rangeProtections[i].getEditors();
protection['description'] = rangeProtections[i].getDescription();
protection['range'] = rangeProtections[i].getRange();
protection['unprotected ranges'] = rangeProtections[i].getUnprotectedRanges();
protection['candomainedit'] = rangeProtections[i].canDomainEdit();
protection['iswarningonly'] = rangeProtections[i].isWarningOnly();
rangeProtections[i].remove();
protectionData.rangeProtections.push(protection);
}
try {
/**
*
* HERE YOU CAN RUN YOUR SCRIPT
*
**/
catch(e) {
Logger.log("Caught exception: " + e.toString());
}
for (var i=0; i<protectionData.sheetProtections.length; i++) {
var sheet = protectionData.sheetProtections[i]['range'].getSheet();
var protection = sheet.protect()
.setDescription(protectionData.sheetProtections[i]['description'])
.setRange(protectionData.sheetProtections[i]['range'])
.setUnprotectedRanges(protectionData.sheetProtections[i]['unprotected ranges'])
.setDomainEdit(protectionData.sheetProtections[i]['candomainedit'])
.setWarningOnly(protectionData.sheetProtections[i]['iswarningonly']);
var protectionEditors = protectionData.sheetProtections[i]['editors'];
// add Editors
for (var j=0; j<protectionEditors.length; j++) {
protection.addEditor(protectionEditors[j]);
}
}
for (var i=0; i<protectionData.rangeProtections.length; i++) {
var range = protectionData.rangeProtections[i]['range'];
var protection = range.protect()
.setDescription(protectionData.rangeProtections[i]['description'])
.setDomainEdit(protectionData.rangeProtections[i]['candomainedit'])
.setWarningOnly(protectionData.rangeProtections[i]['iswarningonly']);
var protectionEditors = protectionData.rangeProtections[i]['editors'];
// add Editors
for (var j=0; j<protectionEditors.length; j++) {
protection.addEditor(protectionEditors[j]);
}
}
}
The idea would be to actually run your script's code where the HERE YOU CAN RUN YOUR SCRIPT
comment is located, which is the point at which the protections are removed from the Sheet and saved in memory. Afterwards, they are retrieved from memory and put back into the Sheet.
You must be careful, however, of the actual script exceeding the runtime limit (see quotas). If this situation occurs, the script will halt without re-setting your protections.
In case you are interested about protections in Google Apps Scripts, I suggest you check out the following link: