Here's a start: It covers many cases, and could be made smarter. You could put it on a menu item or buton for convenience:
Names Default To Here(1);
// Open a table to play with
dt = Open("$SAMPLE_DATA\Big Class.jmp");
// Open some windows in the session from this table (this would be done interactively)
ss = dt << Get Table Script Names;
for (s=1, s<=NItems(ss), s++, dt << runScript(ss[s]));
// Delete the saved scripts from the table
for (s=1, s<=NItems(ss), s++, dt << deleteTableProperty(ss[s]));
Wait(3);
// Start here . . .
// See the names of all the tables that are currently open in ths session
openTables = {};
for(t=1, t<=NTable(), t++, InsertInto(openTables, DataTable(t) << getName));
// See which windows are currently open in the session
openWindows = {};
for(w=1, w<=NItems(Window()), w++, InsertInto(openWindows, Window(w) << getWindowTitle));
// Handle each open table in turn
for(t=1, t<=NItems(openTables), t++,
// Truncate the table name if required
if(EndsWith(Uppercase(openTables[t]), ".JMP"), openTables[t] = Substr(openTables[t], 1, Length(openTables[t])-4));
for(w=1, w<=NItems(openWindows), w++,
If(StartsWith(openWindows[w], openTables[t]),
// This windows belongs to this table, so get the scriptable object
so = Window(openWindows[w])[OutlineBox(1)] << getScriptableObject;
// Save the script to the parent data table
so << saveScriptToDataTable;
// Close the window
Window(openWindows[w]) << closeWindow;
);
)
);