0
votes

I have folder with google spreadsheets, each with it's own app script. So when I want to change something in script, I need to open each spreadsheet (10+) then open script editor and then change. I know I can make library but google discourages the practice and my initial attempts at making library were tiresome, so I would rather do it this way. The setup uses google app scripts to read twitter timelines using OAuth1 library.

So the question is: I want a universal find and replace that can change code within app scripts which are part of google spreadsheets.

To avoid trouble of creating ui, I can create a new spreadsheet and designate two cells for find and replace text but what do I write in it's script editor? How do I reference all scripts within spreadsheets within that particular folder?

I hope it's not very confusing. Folder > many spreadsheets > each has apps script. Want find and replace in apps scripts within entire folder.

Edit: Code Example.

var scriptIds = new Array("MRZbGCeTKBmp4CtqXXgos-8aNDKt3pcCO","MNOZVgBdOeoAQzms4suAKhg6in9ksdb4l","MEe5136smpZ6I6GcgDuCuB8aNDKt3pcCO");
function myFunction() {
  for(i = 0; i < scriptIds.length; i++){ 
    var doc = DocumentApp.openById(scriptIds[i]);
   doc.replaceText("My search string or regex", "My replacement string");
}
 Logger.log("Done");
}

The Ids in array scriptIds are project Ids of apps script files (which themselves are attached to individual spreadsheet files) that I've added manually.

1

1 Answers

0
votes

You can loop over the sheets using their ids in the single script. You have not pasted the code or I could show you where to change it. Either store the ids in an array or use DriveApp to loop over files in the folder and get their ids.

Then the rest of the code you can put inside the loop and it should work.