These things are always more complicated than they look on the surface :-). Save this to a text file and put this in the startup folder and it should do the switching to the active book automatically when the last active document is closed. Any feedback is appreciated.
#target framemaker
var CP = CP || {};
CP.getAllOpenVisibleDocs = function () {
var docs, doc;
docs = [];
doc = app.FirstOpenDoc;
while (doc.ObjectValid () === 1) {
if ((doc.IsOnScreen === 1) && (doc.Label !== "Structure View")) {
docs.push (doc);
}
doc = doc.NextOpenDocInSession;
}
return docs;
};
Notification (Constants.FA_Note_PostQuitDoc, true);
function Notify (note, object, sparam, iparam) {
var docs, book;
switch (note) {
case Constants.FA_Note_PostQuitDoc:
// See how many documents are open and visible.
// The Welcome screen will not report as the active document.
docs = CP.getAllOpenVisibleDocs ();
if (docs.length === 0) {
// No active document; see if a book is open.
book = app.FirstOpenBook;
if (book.ObjectValid () === 1) {
// A book is open; make it active.
app.ActiveBook = book;
book.IsInFront = 1;
}
}
break;
}
}