Maybe you can do the following, have a try:
Step 1: You need to insert in every script the following function at the top:
function MyScriptID(){return ScriptApp.getScriptId()}
Step 2: using a separate spreadsheet to manipulate data (a kind of master sheet), you will run the following function:
function FindScriptID() {
// Insert the ID of the sheet you want to retrieve the script Id from
var sheet = SpreadsheetApp.openByUrl('your ID')
// name the sheet where you want to insert the formula
var destination = sheet.getSheetByName("mysheet");
// Choose a cell to insert the formula - example: (4,2)
destination.getRange(4, 2).setFormula('=MyScriptID()');
SpreadsheetApp.flush();
// get the displayed ID from the formula, which is actually the ID of the attached script
var myscriptID = destination.getRange(4, 2).getDisplayValue();
Logger.log(myscriptID)
// You can now write the ID of your script within the sheet you've ran the above function, choose a sheet where you wan to write the ID - e.g. Sheet1
var currentsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
//Choose a cell to write the link of you your script or just the ID
currentsheet.getRange(2, 2).setValue('https://script.google.com/a/ais.sch.sa/d/' + myscriptID + '/edit')
}
You can now improve this master sheet if you have many spreadsheets to work with in order to iterate though all of them in one go:
Within the master sheet:
- You list all your spreadsheets (urls)
- you include in all their scripts (
function MyScriptID(){return ScriptApp.getScriptId()}
) at the top as mentioned before
- you iterate through all the spreadsheet links to insert the formula
- You read the displayed values
- You write into the master sheet the retrieved scripts IDs or links
You'll get sometimes some errors with the displayed values, like ('Loading...'
)